Required fields, when displayed as "select list", should not have a default value.
Since there is no "null" (or "unset", etc.) value in "select list" options, implicitly, a default selection is made. In many cases, this makes no sense, for example for a "title" selection list, with the values "Mr.", "Ms." and "Mrs." - you can't make a reasonable assumption about the user's sex.
Required fields are made required because you want the user to make a conscious selection - some users are going to just click through without making a selection, because they can. That misses the point of making the field required.
Therefore, the first (and default) option for selection lists should be "--", or "please make a selection", etc. - as per dropdowns around Drupal and various other modules in general.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | optionwidgets.module.patch | 546 bytes | anrikun |
Comments
Comment #1
jeff.k commentedI fully agree. If it is not preset to Null, anyone missing a field will not be prompted to select one. The result will just be a lot of false selections.
Comment #2
aharown07 commentedMe too
Comment #3
matteogeco commentedSubscribe, I believe this is an old and controverse issue, CCK 5.x had this problem too and I never found a solution!
Comment #4
adamo commented+1
Comment #5
grendzy commentedI agree that this is a problem.
I have found a workaround: You can include a "null" first item in your allowed value list by using an empty string for the key. If a user selects this "null" item the form will not validate. So for example you could put this in your allowed values list:
|-- Please select --
mr|Mr.
ms|Ms.
mrs|Mrs.
Since this is actually quite flexible, perhaps the only "fix" needed is to better document this behavior.
Also see core issue #206844: Select elements which are required can be submitted without any user input
Comment #6
maudik commentedSubscribe
Comment #7
hlopes commented|-- Please select --
That workaround doesn't work that well, the field will be printed even if no selection has been made.
EDIT #1:
A better way to do it is using the following syntax.
< none >|-- Please select --
(without spaces)
That'll do.
Comment #8
Gabriel R. commentedThe workaround is also breaking the View filter based on that field.
An optional filter will show the options ALL and --Select--
Comment #9
Gabriel R. commentedEveryone interested in this issue should check out this module CCK Required Single Select http://drupal.org/project/cck_required_single_select
Comment #10
aharown07 commentedHey, great. Thanks!
Comment #11
anrikun commentedNeither #5 nor the cck_required_single_select module appeared to be good solutions to me.
The simple attached patch fixes this issue.
Comment #12
Poieo commented@arnrikun - Tried your patch. Although this does add a blank field, Drupal still validates that field as 'blank' and accepts it as a valid submission. So this really doesn't work for a required field...which is the point of this thread.
Edit: Clarifying...it does not validate if using with the Content Profile module...not sure about a standard CCK form.
Comment #13
anrikun commentedLet's mark this as Needs review again then.
Comment #14
waltWright commentedDoes anybody have any workarounds to be sure that a user verifies the content in a required field of any kind so that the lazy user doesn't accept the incorrect default?
Although CCK Required Single Select module works well for a select list, it does not support other types, including Node References.
This bug (it is a bug) has been present for years and it is difficult to understand why the issues keep getting closed with no solution. I have not seen any workarounds either, for example a dummy value and php to be sure that dummy value isn't selected.
Comment #15
anrikun commented@walt: This issue is about "select" only. Please open a separate issue about other fields.
Comment #16
sinasalek commentedI also think that required fields should be non selected/empty by default
Comment #17
kndrUse this minimodule http://drupal.org/node/789116#comment-3365604 It works without patching optionwidgets module.
Comment #18
waltWright commentedThanks! At first install, this appears to work very well and very simply, until the core functionality catches up (or the bug is fixed). Much appreciated.
Comment #19
anrikun commented@kndr: if you think that your mini-module is better than patch at #11, please provide a patch-for-CCK version of your mini-module. It would be better if this could directly get fixed in CCK without the use of an extra module.
Comment #20
kndr@anrikun: I don't think, that minimodule is better than #11 but long waiting for commit could be frustrating. Minimodule is the alternative way.
Comment #21
anrikun commented@kndr: I meant that many people seem to find your mini-module useful and that it fixes the problem. So if you have time for it, please turn it into a real patch for CCK. This way, your code could be reviewed and committed, and the bug could be fixed in CCK.