Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Really? Cfselect required

Guest
Jul 14, 2009 Jul 14, 2009

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

1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 14, 2009 Jul 14, 2009

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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 14, 2009 Jul 14, 2009

Your assumptions are correct.

All the other cf validation works (cftextarea, cfinput, etc).  Just not on the cfselect field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 14, 2009 Jul 14, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 14, 2009 Jul 14, 2009

Really.  The required attribute of cfselect really does not do anything.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

I've got the same problem... there is a solution that works for some people... maybe you'll be one of the lucky ones.

Solution

Good luck

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 19, 2010 Mar 19, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2013 Jan 24, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 30, 2013 Jan 30, 2013
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources