"Placeholder" form display input gone after update?

Created on 25 September 2023, about 1 year ago
Updated 31 October 2023, 11 months ago

Problem/Motivation

After the latest update, the Placeholder doesn't show in the form field (screenshot 1) and isn't available on the form display settings (screenshot 2). The placeholder shows in the form display preview (screenshot 3).

Is this a bug?

πŸ“Œ Task
Status

Fixed

Version

1.3

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States chucksimply

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

Comments & Activities

  • Issue created by @chucksimply
  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    Placeholder isn't and shouldn't be an option for non-textfield elements. It only previously existed in the configuration because the field widget is extended from the core autocomplete widget. It had been removed in https://git.drupalcode.org/project/choices_autocomplete/-/commit/bb96a58....

    When using the field widget with a select field type the "placeholder" is the blank/empty/unselected value. In the example you provided the "- Select -" placeholder is the aforementioned option on the select. You can see how Drupal is setting that value in https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co....

    Not a bug. If you need to change the default empty value label a form alter might get the job done.

  • Status changed to Active about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States chucksimply

    Thanks @robphillips for the reply. It looks like the value is being set in src/Element/ChoicesAutocomplete.php on line 67.

    I've tried the below form alter with no success...

    $form['field_choices_field']['widget']['target_id']['#empty_option'] = t('New placeholder text');

    Any other tips for modifying this empty option (without needing to write a custom patch for the module itself)?

    If we can post a solid solution, I'm sure it will help other module users in a similar boat. Thanks!

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    The searchPlaceholderValue configuration is still valid. Only placeholder has been deprecated because it's intended for text inputs. The configuration is labeled as "Start typing text".

  • Status changed to Active 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States chucksimply

    Thanks for the reply, although searchPlaceholderValue doesn't help change the - Select - text. Only way I could do it was with the below hook. Would be nice if there was a better solution, but this will have to do for now.

    function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
      if (isset($form['field_choices_field']['widget'])) {
        $form['field_choices_field']['widget']['#process'][] = '_yourmodule_modify_placeholder';
      }
    }
    
    function _yourmodule_modify_placeholder(&$element, &$form_state, &$complete_form) {
      if (isset($element['#options'][''])) {
        $element['#options'][''] = t('Select water');
      }
      return $element;
    }
    
  • Status changed to Closed: works as designed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States chucksimply
  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    Re-opening to add new configuration to override the "none" label on standard select elements.

    • 391d8acb committed on 1.x
      Issue #3389626: Add configuration to change no selection text on...
  • Assigned to robphillips
  • Status changed to Fixed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States robphillips
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States chucksimply

    Thanks for this @robphillips, although on module update, the form display doesn't show the new "No selection text" input field. I don't see none_text updated in the configuration files either. Am I missing something? Do these config files need to updated?

  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    It's at the bottom and only available on standard select fields.

  • πŸ‡ΊπŸ‡ΈUnited States chucksimply

    What do you mean by standard select fields? So doesn't work for entity reference fields? Here are my form display settings for this field.

  • πŸ‡ΊπŸ‡ΈUnited States robphillips

    A standard select is any "List (Type)" field or otherwise select element in a form. You could use the "Start typing text" as the placeholder for entity reference fields. However, I've realized now that it only works when the entity reference field allows more than 1 selection. Because Choices.js changes how it displays selections and inputs between allowing 1 or multiple selections.

    I've created πŸ“Œ Extend no selection text to entity reference fields Active to extend the no selection text to single value entity reference fields.

  • πŸ‡ΊπŸ‡ΈUnited States chucksimply

    Gotcha... thanks for the explanation, makes sense. And I appreciate you creating that new issue. Following.

Production build 0.71.5 2024