Copy link to clipboard
Copied
I have done some research on cfselect validation being useless but I have a hard time believing it. I have tested it on my own and cannot get the tag to work.
How do I get cfselect to require a selection?
<cfselect name="bobby" required="yes" message="Select something please.">
<option value="" selected></option>
<option value="red">red</option>
</cfselect>
Doesn't work... allows me to select nothing without a prompt
Copy link to clipboard
Copied
I presume that is inside a <cfform...> tag, but your code snippet did not show this.
I presume that JavaScript is enabled in the browser being tested.
I presume that the /cfide/scripts/ directory is accessible for the required JavaScript files.
I presume that you realize putting the selected parameter on a option means that something HAS been selected.
<option value="" selected></option>
Copy link to clipboard
Copied
Your assumptions are correct.
All the other cf validation works (cftextarea, cfinput, etc). Just not on the cfselect field.
Copy link to clipboard
Copied
idesdema wrote:
All the other cf validation works (cftextarea, cfinput, etc). Just not on the cfselect field.
It is working, just not the way you are thinking. The built in validation does not care about the option "values". It only checks that _some_ option is selected, regardless of the "value". As Ian pointed out, something IS selected. So there is no error.
If you look at the internal javascript used for cfselect validation it is really geared towards multiple selection lists. Not single (as you are using). So you may need to write your own validation.
http://cfsearching.blogspot.com/2008/11/cfselect-requiredtrue-well-not-really.html
Copy link to clipboard
Copied
Really. The required attribute of cfselect really does not do anything.
Copy link to clipboard
Copied
I've got the same problem... there is a solution that works for some people... maybe you'll be one of the lucky ones.
Good luck
Copy link to clipboard
Copied
I have the same problem... sometimes.
I already implemented the fix WTG mentions which has allowed the validation to work for a long time now.
However suddenly a few people are "sneaking through" the validation and I don't know why. I get error notifications and so far the only common thread I see is that they are running IE8 (most of our users are still on IE6 but we are slowly upgrading).
When I try the problem page with an IE8 browser the validation works as expected... so I cannot reproduce the error. But there is an error nonetheless.
There must be more to the story but I'm still looking for it.
Copy link to clipboard
Copied
Simple Solution:
Just make the first option empty as follows:
<option></option>
<option>Apples</option>
<option>Oranges</optioin>
When required=yes this will work ... with no javascript.
HOPE THIS HELPS EVERYONE!
... Jurisdictionary
Copy link to clipboard
Copied
I recently struggled with getting this to work on two separate projects. I ended up relying on the server side validation, but I'd rather have the client first because I think it makes for a better interface.
Thanks for posting this. It helped me out in both spots!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more