ListStringItem is difficult to work with when you have a long pre-defined list

Created on 10 April 2024, 7 months ago
Updated 17 April 2024, 7 months ago

Problem/Motivation

In 📌 List key|label entry field is textarea, which doesn't give guidance towards the expected input Fixed changes were made to ListStringItem. This used the machinename element. However it is extremely difficult to work with compared to ListIntegerItem. The user has to constantly click "edit" to keep the Value text field open. It automatically is closed/hidden whenever the "Name" changes or if the value itself is changed.

Trying to recreate the List (string) example of a US state picklist is painful.

'US States': IL => Illinois, IA => Iowa, IN => Indiana

Not to mention, the "Machine name:" prefix alongside the input.

Steps to reproduce

Proposed resolution

Stop using the machine name element so that users can define their own key/value much more easily.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Options 

Last updated 9 days ago

No maintainer
Created by

🇺🇸United States mglaman WI, USA

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

Comments & Activities

  • Issue created by @mglaman
  • 🇺🇸United States mglaman WI, USA
  • 🇫🇮Finland lauriii Finland

    I'm wondering if we should introduce the textarea as an advanced option on top of the current option guided option so that you could do a bulk update multiple values easily, as well as copy and paste a list from a text editor. What I'm thinking is adding a link on top of the table with a text "Bulk edit", which would open a modal dialog with the values in a single textarea. Once you submit the form on the dialog, it will automatically populate the table based on the values you've given in the dialog. This way we would probably get best of both worlds.

  • 🇺🇸United States mglaman WI, USA

    #3 sounds like a good idea for power users, as well. It'd be good to know if the | makes sense or CSV? Or this is now fledging into contrib territory. I'll do some research on how picklist fields are handled in some other systems

  • 🇺🇸United States mglaman WI, USA

    The current UI kind of matches what Contentful has - where there is only the value/name and no internal value:

    The issue is when you intend to use the List field as a key/value versus a general list of predefined values.

  • 🇺🇸United States mglaman WI, USA

    Okay, I found the source of one of my "problems." With \Drupal\field_ui\Form\FieldConfigEditForm::addAjaxCallbacks every input for a field storage setting triggers AJAX and a form rebuild. This is what was causing the machine name to constantly switch from an editable input to a label.

  • Assigned to mglaman
  • 🇺🇸United States mglaman WI, USA

    I'm working on some ideas, I'll assign this to myself for now.

  • 🇺🇸United States mglaman WI, USA

    We worked on some versions of this, and it was equally difficult/confusing on what the toggle for customizing values did.

    One thing I found that made an improvement was customizing the machine-name's "label" property to "Value:

    $element['allowed_values']['table'][$delta]['item']['key']['#machine_name']['label'] = $this->t('Value');
    

    There is still the problem where any text input change causes the entire form to reset and close the machine-name elements.

Production build 0.71.5 2024