When there is no saved value for a select list, drupal does not set a default value.
This is fine in most circumstances, however, if the select list is ever sorted by a method other than the default ordering, the "- None -" value is not preselected.

To reproduce:
In a form alter for a node edit form, call asort() on a field's option list. This drops the "- None -" option lower in the list.
Choose the "- None -" option and save the form.
On reloading the form, the first element on the list will be preselected, not because of the selected attribute, but simply because it is the first element in the list.

Patch supplied to set the default value of the list to "- None -" when no saved value is found.

Comments

DaneMacaulay’s picture

Issue tags: +Patch provided
StatusFileSize
new665 bytes

The last submitted patch, field-provide-default-value-for-select-1971204-1.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

typo

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.