|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Validation of a select Menu using <cfselect>
Hi Everyone. I am running into a problem validating a select menu usingJohn Cowie 02/15/01 04:08 P try to change <option selected></option>Mak Wing Lok 02/15/01 09:16 P Make it <option value=""></option>Bryan LaPlante 02/15/01 10:38 P I just found this posted by a user in the LiveDocs and it works great!Phillip Molaro 07/14/05 04:12 P Thanks, Phillip --Heather Harkins 05/08/08 10:57 A > Your fix is great - if you control your own CF Server, but ifDave Watts 05/08/08 12:24 P Hi Everyone. I am running into a problem validating a select menu using <cfform>. All of my <cfinput> tags are validating fine but the select menu doesn't seem to be working. Here is the code that I am using. If anyone can see what I am doing wrong I would appreciate the help. Thanks in advance John <cfform action="addrecord.cfm" method="POST"> <cfselect name="Status_Field" size="1" message="Please select a category" required="Yes"> <option selected></option> <option value="Member">Member</option> <option value="Non-Member">Non-Member</option> <option value="Student">Student</option> <option value="Educator">Educator</option> </cfselect> </cfform> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm try to change <option selected></option> to <option></option> ----- Excess quoted text cut - see Original Post for more ----- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Make it <option value=""></option> ----- Excess quoted text cut - see Original Post for more ----- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm I just found this posted by a user in the LiveDocs and it works great! What you need to do is to edit the javascript that the CF server writes so that it also checks for a null value (your value="" part of your first option item). This is a simple code change in a javascript template file. Edit this file: C:\CFusionMX7\wwwroot\CFIDE\scripts\cfform.js Inside this file, modify line #73 this way: ORIGINAL: else if (obj_type == "SELECT") { for (i=0; i < obj.length; i++) { if (obj.options[i].selected) return true; } return false; } MODIFIED: else if (obj_type == "SELECT") { for (i=0; i < obj.length; i++) { if (obj.options[i].selected && obj.options[i].value != "") return true; } return false; } You may need to restart your coldfusion service, but otherwise this will work with the standard required="yes" method in your cfselect tag. Giving credit where credit is due: http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Tags91.htm Thanks, Phillip -- This is something that has irked me for years. Due to its limitations, I've never really used CFFORM extensively, but I thought I'd give it a go for a new project and hit this immediately. Your fix is great - if you control your own CF Server, but if you've got a client who's on a shared box, then you need another work-around. My charming husband has a solution: So, you take the SERIOUSLY FLAWED CFSELECT-generated validation function (called _CF_hasValue) and set it to a new variable, called _CF_hasValue_old. Then, you run through your NEW function, now called by the original one's name. If the function finds a select box of size 1 on the form, it will loop through the values until it finds one that is not only SELECTED but also has a VALUE (the latter little tidbit is NOT something that CF validation checks for. Ridiculous!). If it finds one, it breaks out of the function. Otherwise, it continues on and will returns false. On the other hand, if the field in question isn't a single-select, then the old CF Validating function will run. ** Caveat: this assumes that Adobe's not going to be changing the names of any functions with newer versions... ?? So use at your own risk. So, for example, I configured my form like this (using attribute "queryposition" to manage my valueles OPTION tag relative to my query output): <CFFORM... blah blah> <CFSELECT name="ThingID" required="Yes" size="1" queryposition="below" message="Please make a Thing selection." value="ThingID" query="qThingTypes" display="Things"> <OPTION>Please select a Thing Type</OPTION> </CFSELECT> <[SUBMIT]> </CFFORM> <SCRIPT> var _CF_hasValue_old = _CF_hasValue; _CF_hasValue=function(_b,_c,_d) { if (_b.type == 'select-one') { var bSelected = false; for (var i=0; i<_b.options.length; i++) { if (_b.options[i].selected == true && _b.options[i].value != '') { bSelected = true; break; } } return bSelected; } else return _CF_hasValue_old(_b,_c,_d); } </SCRIPT> ================================================================== ----- Excess quoted text cut - see Original Post for more ----- htm > Your fix is great - if you control your own CF Server, but if > you've got a client who's on a shared box, then you need > another work-around. No, you can just copy the existing JS files to your own directory, then use the SCRIPTSRC attribute of CFFORM. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Training: Adobe/Google/Paperthin Certified Partners http://training.figleaf.com/ WebManiacs 2008: the ultimate conference for CF/Flex/AIR developers! http://www.webmaniacsconference.com/
|
May 25, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||