Problem/Motivation

When I use the checkbox/radio format, the "- None -" option is often missing.

Steps to reproduce

I can't tell why some of my fields have it and some do not. They are all taxonomy reference fields with the exact same settings.

However, a fresh test reproduces the error for me.

Create a new entity reference field for a taxonomy vocabulary.
Change the field to "select or other" in the form display.
Change select list to checkboxes.

The "- None -" option is missing.

Proposed resolution

I have altered this code to check that the array contains no default items, rather than just if the array exists.

  protected static function addEmptyOption(array &$element) {
    if ((!isset($element['#no_empty_option']) || !$element['#no_empty_option']) && !$element['#multiple']) {
      if (!$element['#required'] && !count($element['#default_value']) > 0) {
        $element['select']['#options'] = ['' => t('- None -')] + $element['select']['#options'];
      }
      else {
        $element['select']['#value'] = [];
      }
    }
  }

This seems to work for me. I would welcome some thoughts on it or if this is an issue for anyone else.

I can also confirm this issue, however, I don't think it's 100% directly related to my issue:
https://www.drupal.org/project/select_or_other/issues/3260054

CommentFileSizeAuthor
#2 missing-none-option-3463820-1.patch662 bytesxpersonas

Comments

xpersonas created an issue. See original summary.

xpersonas’s picture

StatusFileSize
new662 bytes