Verified Commit bf07341e authored by Juraj Nemec's avatar Juraj Nemec
Browse files

Issue #1530486 by poker10, chimericdream: [D7] list_field_validate() doesn't...

Issue #1530486 by poker10, chimericdream: [D7] list_field_validate() doesn't seem to accommodate select lists with <optgroup>
parent c63d29bd
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -388,7 +388,8 @@ function _list_values_in_use($field, $values) {
 * - 'list_illegal_value': The value is not part of the list of allowed values.
 */
function list_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  $allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);
  // Flatten the array before validating to account for optgroups.
  $allowed_values = options_array_flatten(list_allowed_values($field, $instance, $entity_type, $entity));
  foreach ($items as $delta => $item) {
    if (!empty($item['value'])) {
      if (!empty($allowed_values) && !isset($allowed_values[$item['value']])) {
+5 −0
Original line number Diff line number Diff line
@@ -311,6 +311,11 @@ class OptionsWidgetsTestCase extends FieldTestCase {
    $edit = array("card_1[$langcode]" => '_none');
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array());

    // Submit form: select the option from optgroup.
    $edit = array("card_1[$langcode]" => 2);
    $this->drupalPost(NULL, $edit, t('Save'));
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array(2));
  }

  /**