Forms: Requiring a dropdown selection

I'm struggling with an aspect of a form where I want to force users to select an option from a drop-down (the list is a bit long to have as a set of radio buttons).


I thought that the complex validation rule "Must select exactly this many options" would do the trick, but in fact it has no effect as the form treats the default option as a selection (even if it is the empty option).



Should the empty option really be counted when checking the number of options selecteds? Any other suggestions?

[quote]
I'm struggling with an aspect of a form where I want to force users to select an option from a drop-down (the list is a bit long to have as a set of radio buttons).



I thought that the complex validation rule "Must select exactly this many options" would do the trick, but in fact it has no effect as the form treats the default option as a selection (even if it is the empty option).



Should the empty option really be counted when checking the number of options selecteds? Any other suggestions?

[/quote]



Hi Nick,



You're using an tickbox list? Probably a silly question, but could you use the 'Required Entry' attribute in the simple validation rules to do this?

[quote]
You're using an tickbox list? [/quote]



No, I'm using a drop down box. <select><option><option> etc.



A radio list would be the alternative as I only want one option selected (no more, no less) but as I said I would prefer not to use one as it would be rather long (I'm talking about 27 options here).

[quote]
No, I'm using a drop down box. <select><option><option> etc.



A radio list would be the alternative as I only want one option selected (no more, no less) but as I said I would prefer not to use one as it would be rather long (I'm talking about 27 options here).

[/quote]



If you only want one option selected, why not just remove the blank option and just have a listing of your options?

[quote]
If you only want one option selected, why not just remove the blank option and just have a listing of your options?

[/quote]



If I do that the first option in the list becomes the default option, which is worse since I can't then distinguish the lazy from people who selected that option deliberately.



I know that dropdowns lists can't (strictly speaking) submit a blank response - by itself it will treat any responses equally. However, given that the CMS does have this as an option I would have thought it possible for the form validation to treat the "blank response" differently. It leaves me wondering what the point of the option is as it seems to produce an identical effect to adding the "blank" option to the start of my option list.

[quote]
If I do that the first option in the list becomes the default option, which is worse since I can't then distinguish the lazy from people who selected that option deliberately.



I know that dropdowns lists can't (strictly speaking) submit a blank response - by itself it will treat any responses equally. However, given that the CMS does have this as an option I would have thought it possible for the form validation to treat the "blank response" differently. It leaves me wondering what the point of the option is as it seems to produce an identical effect to adding the "blank" option to the start of my option list.

[/quote]



You could always try some live validation with javascript/jquery if you want to get your hands dirty (and you're happy using js). I imagine something like –



[indent]var doCheck = function( e ){

[indent] // a function to validate the form

var dropdown = $( "#yourSelectId" );

if ( dropdown.val() === "" ){ // CHECK EMPTY[indent]

return false;[/indent]

}



return true;[/indent]

};



// bind the event to the form

$( "#yourFormId" ).submit( doCheck );[/indent]



– would do the trick. Maybe even turning on 'Live Validation' might do something too, without the need to write code.

I shouldn't really have to do that though - Matrix knows that the first option is "blank", so when I use the native functionality to check for "exactly 1" or "at least 1" selection it shouldn't be treating the blank as a selection (should it?).