- Issue created by @chucksimply
- Status changed to Closed: works as designed
about 1 year ago 7:41pm 26 September 2023 - πΊπΈ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 9:01pm 26 September 2023 - πΊπΈ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 6:02pm 28 September 2023 - πΊπΈUnited States robphillips
The
searchPlaceholderValue
configuration is still valid. Onlyplaceholder
has been deprecated because it's intended for text inputs. The configuration is labeled as "Start typing text". - Status changed to Active
about 1 year ago 9:18pm 2 October 2023 - πΊπΈ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
about 1 year ago 9:30pm 2 October 2023 - Status changed to Needs work
about 1 year ago 2:41pm 16 October 2023 - πΊπΈ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...
- 391d8acb committed on 1.x
- Assigned to robphillips
- Status changed to Fixed
about 1 year ago 3:56pm 16 October 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
about 1 year ago 5:05pm 31 October 2023 - πΊπΈ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.