Drupal 6.15 | CCK 6x-2.6
I have read pages of posts (search results), but have only found the issue for the 3dev version.
I created a text field, widget type select list, with a list of allowed values using the Allowed Values form field. The Default Value is set as -None- (module option); however, the first item (my value) of the select field on node add/edit form is highlighted, rather than it showing -None-, as I expect. The Default Value dropdown does show all of my allowed values. Likewise, the null "n/a" (module value) for radio buttons likewise is not available in Views. Is this default not associated with the allowed values list?
Any other way to set a null default (such as -none-)?
Thank you.
Greta
CCK rocks!
Comments
Comment #1
greta_drupal commentedJust to clarify. I'd like to have a null value (no value) as an allowed option for required fields so that users do not neglect to complete the required field. When the first item of allowed values is highlighted/selected as the default, it thereby fulfills (not necessarily correctly) the requirement.
Creating a dummy value (such as "- select one -") isn't an option as it then creates an erroneous expectation for an exposed field in Views.
Comment #2
bryancasler commentedSame problem.
The first value of any required "select field" is automatically placed into itself. This is a major problem as these fields in the form will always validate on submission.
Comment #3
gdvallance commentedI have the same problem, although I am running the latest version of Acquia Drupal (6.16) -- which uses 6.x-2.x-dev for most of CCK's modules.
EDIT: I have just upgraded to 6.x.2.6 and the problem remains.
In this case, the behaviour occurs if one makes the Select Field required. If it is not required then the default value - None - works. But of course the form will validate, and I too want to force users to enter in a value in such fields.
There is a work-around which forces a choice but unfortunately it leaves a blank field. What you do is add | to the top of the Allowed Values list. E.g. for a choice between Male and Female you would insert:
Credit goes to: http://drupal.org/node/182946 for this interim solution.
Comment #4
Reynar commentedGuys, there is no problem at all... Just use it like (for example):
It works!
Comment #5
gdvallance commentedIt does indeed work.
I thank you for this. It is a great workaround, and I now understand more about the select lists. :-)
However, I would suggest that there still is a problem that needs to be fixed, unless there are changes to the instructions to say you must put in paired values. The instructions at present say you only need to put a single value list.
Surely, a REQUIRED field setting should not add a default value to a field when you configure the system elsewhere NOT to add a default value to a field.
Comment #6
bryancasler commentedI was not able to get this working, if nothing is selected then the "Please select required field" is still submitted.
Comment #7
greta_drupal commentedNo. That does not give a null value option.
Comment #8
cwebster commentedI just created a new module that I think will solve this problem for you: http://drupal.org/project/cck_required_single_select . Let me know what you think!
Comment #9
agileware commentedRe the original post:
Doesn't cck do this automatically when you un-check the 'Required' checkbox for the field? It does for me.
If a select IS NOT REQUIRED then the null value option is handled automatically by cck.
- Then if you want to make sure you have not selected -none- you have to custom validate.
OR
If the select field IS REQUIRED and you want a -none- option then you have to add it yourself in the allowed values (see #4).
- Note that if the field is required I think that the database field is set to not allow NULL values.
Then, with or without the cck-added -none- value the first item is selected.
If yours does not select the first item there is possibly something in the settings of your field and allowed values that is messing it up.
@animelion (#2)
That is just how the select fields work. If you want to force selection you have to do custom validation or add a new cck feature request issue.
-- Changing status, critical is for bugs that break your site or make the module not work. --
@cwebster (#8)
Couldn't the functionality of that new module be added to cck with a feature request patch?
It seems like functionality that should belong in CCK.
Comment #10
cwebster commentedSounds great to me. I'm not sure I know enough to know where to start. Any pointers? I would definitely like to see this in CCK.
Comment #11
bryancasler commentedEveryone interested in this issue should check out this module CCK Required Single Select http://drupal.org/project/cck_required_single_select
Comment #12
agileware commented@cwebster
I have not looked into it much but if I get some time I will report back here any findings.
@animelion
That was already mentioned in #8
Comment #13
focal55 commentedThank you @animelion that module saved my afternoon.
Comment #14
cwebster commentedI do want to clarify that I think the functionality of the CCK Required Single Select module could be much more cleanly and logically incorporated into CCK itself. My proposal would be to allow users to enter a "special" option value (before the pipe) for a select option that displays, but does not validate. The two examples that come to mind are:
Also, it would be great if this behavior worked for multiple-value select lists as well. Any thoughts?
Comment #15
Coupon Code Swap commentedAgreed 100%. This functionality should be incorporated in CCK. A required field should require that the user take action, rather than automatically selecting a value as default.
Comment #16
YK85 commented+1 subscribing
Comment #17
dwightaspinwall commentedI believe the solution is per #4, but don't put any text before the pipe character. This will be interpreted as NULL and trigger failed validation.
Comment #18
Gabriel R. commented@cwebster #8 I can confirm that this module does the job, and is also fixing the problem with the -Select- option being listed in View filters.
Comment #19
anrikun commented+1 subscribing
Comment #20
dkg commentedI'm seeing this issue also for nodereference types. It's particularly troublesome there, because users who neglect to inspect the field will automatically select the first listed node, which is almost certainly wrong.
Comment #21
dkg commentedTo be clear, the relevant (not-uncommon) corner case is when exactly one node must be referenced by the user.
In that case, for the new content form, the select box should start off with a "none" item, which is initially selected, but will not validate.
For an edit content form from an already-validated node, the select box should not include the "none" item.
Comment #22
tstackhouse commented+1 subscribing
Comment #23
greta_drupal commentedHow is this still an issue, for a cornerstone Drupal module, 21 months since I posted it.
Try this module: http://drupal.org/project/values
Comment #24
atodorov commentedsubscribing