- None - option for default value in field settings form is being removed

Created on 24 January 2022, over 2 years ago
Updated 1 June 2023, about 1 year ago

The "- None -" option in the "default value" area of a field's settings form seems to disappear when the "select or other" widget is enabled. This makes is impossible to save changes to the settings of a single select field without choosing a default value for the field. Can anyone else confirm this issue?

The only workaround I can find is to switch the widget back to the core select list widget, modify and save the field settings, then re-enable the "select or other" widget.

The problem seems related to the "#no_empty_option" value being set to 1 when the select or other module builds the widget in the context of a settings form.

By the time the following code in /select_or_other/src/Plugin/Field/FieldWidgetWidgetBase.php is called, the value of that variable is 1 rather than 0 or empty:


  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element += [
      '#no_empty_option' => $this->isDefaultValueWidget($form_state),
      '#type' => $this->getSetting('select_element_type'),
      '#default_value' => $this->getSelectedOptions($items),
      '#multiple' => $this->isMultiple(),
      '#key_column' => $this->getColumn(),
      '#other_placeholder' => $this->getSetting('other_placeholder'),
      '#other_option' => $this->getSetting('other_option'),
      '#other_field_label' => $this->getSetting('other_field_label'),
    ];

    $element['#options'] = $this->getOptions($items->getEntity());
    $element['#options'] = $this->sortOptions($element['#options']);
    // The rest of the $element is built by child method implementations.
    return $element;
  }
πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States isaac77

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024