Issue #2762953 by cilefen, gisle, drumm: Select elements should use strict comparison
parent
7b0d229af1
commit
2893aec5df
|
@ -113,7 +113,7 @@ function form_select_options($element, $choices = NULL) {
|
|||
$option = [];
|
||||
$key = (string) $key;
|
||||
$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)) {
|
||||
if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'], TRUE))) || $empty_choice)) {
|
||||
$option['selected'] = TRUE;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -325,6 +325,49 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$edit = array('card_1' => '_none');
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array());
|
||||
|
||||
// Create field storage with string keys.
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'select_a',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'list_string',
|
||||
'cardinality' => 1,
|
||||
'settings' => [
|
||||
'allowed_values' => [
|
||||
'7.50' => '7.50',
|
||||
'7.5' => '7.5',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
// Create a list_string field instance.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'entity_test',
|
||||
'required' => TRUE,
|
||||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_storage->getName(), array(
|
||||
'type' => 'options_select',
|
||||
))
|
||||
->save();
|
||||
|
||||
// Create and save an entity.
|
||||
$entity = EntityTest::create(array(
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
$entity->save();
|
||||
|
||||
// Ensure string keys are properly marked selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
$edit = array('select_a' => '7.50');
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity, 'select_a', array('7.50'));
|
||||
$this->assertOptionSelected('edit-select-a', '7.50');
|
||||
$this->assertNoOptionSelected('edit-select-a', '7.5');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue