If an empty (null) value is submitted, it could be because no elements should be selected.
I believe form_type_multiselect_value should be more in line with form_type_select_value:
function form_type_select_value($element, $input = FALSE) {
if ($input !== FALSE) {
if (isset($element['#multiple']) && $element['#multiple']) {
// If an enabled multi-select submits NULL, it means all items are
// unselected. A disabled multi-select always submits NULL, and the
// default value should be used.
if (empty($element['#disabled'])) {
return (is_array($input)) ? drupal_map_assoc($input) : array();
}
else {
return (isset($element['#default_value']) && is_array($element['#default_value'])) ? $element['#default_value'] : array();
}
}
// Non-multiple select elements may have an empty option preprended to them
// (see form_process_select()). When this occurs, usually #empty_value is
// an empty string, but some forms set #empty_value to integer 0 or some
// other non-string constant. PHP receives all submitted form input as
// strings, but if the empty option is selected, set the value to match the
// empty value exactly.
elseif (isset($element['#empty_value']) && $input === (string) $element['#empty_value']) {
return $element['#empty_value'];
}
else {
return $input;
}
}
}I will work on a patch tomorrow.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | submitting_an_empty-2742981-2.patch | 440 bytes | daften |
Comments
Comment #2
daften commentedPatch in attachment
Comment #3
daften commentedSetting to needs review
Comment #4
cosolom commentedWorked for me in FAPI mode. Thanks.
Comment #5
mparker17multiselect-7.x-1.11 is no longer supported, because Drupal 7 is no longer supported.
Can you confirm if this is still an issue in multiselect-2.0.0-beta4?
I'm going to mark this issue as "Postponed (maintainer needs more info)"... but when you answer, please change it back to "Active". If there is no reply in ~6 months, then I will mark this issue as "Closed (outdated)". Thank you in advance for your understanding and patience as I try to keep this module's issue queue clear.