diff --git a/includes/form.inc b/includes/form.inc index 846bcb5..81656d7 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -2719,6 +2719,8 @@ function form_select_options($element, $choices = NULL) { // isset() fails in this situation. $value_valid = isset($element['#value']) || array_key_exists('#value', $element); $value_is_array = $value_valid && is_array($element['#value']); + // Check if the element is multiple select and no value has been selected. + $empty_value = (empty($element['#value']) && !empty($element['#multiple'])); $options = ''; foreach ($choices as $key => $choice) { if (is_array($choice)) { @@ -2731,7 +2733,8 @@ function form_select_options($element, $choices = NULL) { } else { $key = (string) $key; - if ($value_valid && (!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) { + $empty_choice = $empty_value && $key == '_none'; + if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $empty_choice)) { $selected = ' selected="selected"'; } else { diff --git a/modules/field/modules/options/options.test b/modules/field/modules/options/options.test index 7183311..cab4e08 100644 --- a/modules/field/modules/options/options.test +++ b/modules/field/modules/options/options.test @@ -320,6 +320,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { // Display form: with no field data, nothing is selected. $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->assertOptionSelected("edit-card-2", '_none'); $this->assertNoOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertNoOptionSelected("edit-card-2-$langcode", 2); diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 665f9ae..4f63ab4 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -1679,7 +1679,9 @@ class TaxonomyTermFieldMultipleVocabularyTestCase extends TaxonomyWebTestCase { // Submit an entity with both terms. $langcode = LANGUAGE_NONE; $this->drupalGet('test-entity/add/test-bundle'); - $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is displayed.'); + // Just check if the widget for the select is displayed, the NULL value is + // used to ignore the value check. + $this->assertFieldByName("{$this->field_name}[$langcode][]", NULL, 'Widget is displayed.'); $edit = array( "{$this->field_name}[$langcode][]" => array($term1->tid, $term2->tid), ); @@ -1718,7 +1720,9 @@ class TaxonomyTermFieldMultipleVocabularyTestCase extends TaxonomyWebTestCase { // The widget should still be displayed. $this->drupalGet('test-entity/add/test-bundle'); - $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is still displayed.'); + // Just check if the widget for the select is displayed, the NULL value is + // used to ignore the value check. + $this->assertFieldByName("{$this->field_name}[$langcode][]", NULL, 'Widget is still displayed.'); // Term 1 should still pass validation. $edit = array(