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

greta_drupal’s picture

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

bryancasler’s picture

Priority: Normal » Critical

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

gdvallance’s picture

Version: 6.x-2.6 » 6.x-2.x-dev

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

|
Male
Female

Credit goes to: http://drupal.org/node/182946 for this interim solution.

Reynar’s picture

Guys, there is no problem at all... Just use it like (for example):

|Please select required field
Male|Male
Female|Female

It works!

gdvallance’s picture

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

bryancasler’s picture

I was not able to get this working, if nothing is selected then the "Please select required field" is still submitted.

greta_drupal’s picture

No. That does not give a null value option.

cwebster’s picture

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

agileware’s picture

Priority: Critical » Normal

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

cwebster’s picture

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

bryancasler’s picture

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

agileware’s picture

@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

focal55’s picture

Thank you @animelion that module saved my afternoon.

cwebster’s picture

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

<none>|Text to Display
<disallow>|Text to Display

Also, it would be great if this behavior worked for multiple-value select lists as well. Any thoughts?

Coupon Code Swap’s picture

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

YK85’s picture

+1 subscribing

dwightaspinwall’s picture

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

Gabriel R.’s picture

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

anrikun’s picture

+1 subscribing

dkg’s picture

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

dkg’s picture

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

tstackhouse’s picture

+1 subscribing

greta_drupal’s picture

How is this still an issue, for a cornerstone Drupal module, 21 months since I posted it.

Try this module: http://drupal.org/project/values

atodorov’s picture

subscribing