Skip to main content
October 7, 2012
Question

<cfselect required="yes"> not working yet?

  • October 7, 2012
  • 2 replies
  • 2352 views

I have been looking all over the coldfusion forums (here and on the net) and it seems this is an ongoing problem with the <cfselect> not being able to validate even though the option is there. Plus it also shows that it available on the adobe cf9 docs that i use for reference, but doesn't wok unless you change a file on the server (according to a solution is found on the net), and we all know not everyone is going to be allowed to rewrite a file on "their" server to make it work. Anyone know or even have an idea why this has been a problem for this long and hasn't been fixed? Some of the forum posts have seen date back a couple of years.

    This topic has been closed for replies.

    2 replies

    Inspiring
    November 13, 2012

    This code works fine for me on CF 9.0.2:

    <cfscript>

              numbers = queryNew("");

              queryAddColumn(numbers, "id", [1,2,3,4]);

              queryAddColumn(numbers, "label", ["Tahi","Rua","Toru","Wha"]);

    </cfscript>

    <cfform name="frm1">

              <cfselect name="number" required="true" message="I said select a bloody number!" query="numbers" value="id" display="label" queryposition="below">

                        <option value="">Select a number</option>

              </cfselect>

              <cfinput type="submit" name="btnSubmit" value="Submit" />

    </cfform>

    <cfdump var="#form#">

    Does this not work for you?

    According to the bug base (which, to be frank, cannot necessarily be trusted), it was fixed in CF9.0.1: https://bugbase.adobe.com/index.cfm?event=bug&id=3040410

    --

    Adam

    Inspiring
    November 13, 2012

    According to the bug base (which, to be frank, cannot necessarily be trusted), it was fixed in CF9.0.1: https://bugbase.adobe.com/index.cfm?event=bug&id=3040410

    Confirmed it does not work in CF 8.0.1, so I guess the bugbase is right!

    --

    Adam

    Participant
    November 13, 2012

    I see the same.

    Works in 9.01

    doesn't in 8.01

    Funny thing; I also couldn't make the queryAddColumn work in 8.01 either.

    Thanks!

    JR

    Inspiring
    October 7, 2012

    Rather than vaguely alluding to issues other people have had without giving any concrete references, can you just describe the problem you're currently having, and provide us with some code that demonstrates it.

    Something like:

    "I want to do [this]. Here is the code I am using.  Instead of doing what I want, it does [this other thing] instead.  I have done some research and ruled out [this], [that], and [the other thing]"

    Then we might have a chance to sort your problem out.

    And I recommend reading this:

    http://www.catb.org/esr/faqs/smart-questions.html

    --

    Adam

    Participant
    November 13, 2012

    I'm having the exact same issue.

    Let me provide some details:

    cfselect always submits the first value, so it's never missing and always passes the "required" test

    Here's my code:

            <cfselect name="event_Type" query="qEventType" display="type" value="type" selected="#cfcMeeting.event_type#" required="yes" message="Please select an Event Type">

    The values consist of  a blank line, and then a few choices.

    The solution cfjunkie refers to is to change the function in the cfform.js file from

    if(_b.options.selected&&_b.options.value.length>0)

       to

    if (_b.options.selected && _b.options.value != '')

    It now works as expected, throwing up a dialog box with your message if the user hasn't selected something other than ""

    As he says, most server admins aren't going to let you change the files in the CFIDE,

    and then they might get updated in the future without your knowledge.

    The solution to this is to use your own local version of cfform.js like this:

        <cfform name="requestForm"  action="#cgi.SCRIPT_NAME#" method="POST" enctype="multipart/form-data" scriptsrc="_scripts/cfform.js">

    This solved the issue for me.

    Unfortunately, it caused another issue in that it broke the little date picker on inputs of type datefield, for example:

        <cfinput type="datefield" name="startDate" id="startDate" size="15" mask="MM/DD/YYYY" value="#dateFormat(cfcMeeting.event_datestart,'mm/dd/yyyy')#" validate="date" required="yes" message="Please enter a Start Date in the form mm/dd/yyyy" />

    Any suggestions?

    Inspiring
    November 13, 2012

    Personally I think the required attribute should be removed from the cfselect tag, but that's just my opinion. 

    As far as what to do, my suggestion is to not use it.  Instead, write your own js function and call it on the form submit event.