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.

CommentFileSizeAuthor
#11 optionwidgets.module.patch546 bytesanrikun

Comments

jeff.k’s picture

I 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.

aharown07’s picture

Me too

matteogeco’s picture

Subscribe, I believe this is an old and controverse issue, CCK 5.x had this problem too and I never found a solution!

adamo’s picture

+1

grendzy’s picture

I 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

maudik’s picture

Subscribe

hlopes’s picture

Title: No option should be selected by default for required select fields » no default selection for required fields
Version: 6.x-2.x-dev » 6.x-2.1
Category: bug » task
Status: Needs review » Active

|-- 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.

Gabriel R.’s picture

The workaround is also breaking the View filter based on that field.
An optional filter will show the options ALL and --Select--

Gabriel R.’s picture

Everyone interested in this issue should check out this module CCK Required Single Select http://drupal.org/project/cck_required_single_select

aharown07’s picture

Hey, great. Thanks!

anrikun’s picture

Title: no default selection for required fields » No option should be selected by default for required select fields
Version: 6.x-2.1 » 6.x-2.x-dev
Category: task » feature
Status: Active » Needs review
StatusFileSize
new546 bytes

Neither #5 nor the cck_required_single_select module appeared to be good solutions to me.
The simple attached patch fixes this issue.

Poieo’s picture

Status: Needs review » Active

@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.

anrikun’s picture

Status: Active » Needs review

Let's mark this as Needs review again then.

waltWright’s picture

Category: feature » bug

Does 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.

anrikun’s picture

@walt: This issue is about "select" only. Please open a separate issue about other fields.

sinasalek’s picture

I also think that required fields should be non selected/empty by default

kndr’s picture

Use this minimodule http://drupal.org/node/789116#comment-3365604 It works without patching optionwidgets module.

waltWright’s picture

Title: no default selection for required fields » No option should be selected by default for required select fields
Version: 6.x-2.1 » 6.x-2.x-dev
Category: task » bug
Status: Active » Needs review

Thanks! 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.

anrikun’s picture

@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.

kndr’s picture

@anrikun: I don't think, that minimodule is better than #11 but long waiting for commit could be frustrating. Minimodule is the alternative way.

anrikun’s picture

@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.