Fixed maximum number of field values, but use «add more» similar to when cardinality «unlimited» is used

Created on 13 May 2011, over 13 years ago
Updated 13 September 2024, 2 months ago

Problem/Motivation

If cardinality of a field is set as 'n', the entity create/edit forms will render the field widget 'n' number of times. It would be nice to render only one widget, and provide an 'Add another item' button to add more field values in such cases, to match the unlimited cardinality behavior.

Steps to reproduce

  • Install Drupal with the standard profile
  • Add a text field to the article content type. Set the cardinality to 4 (limited)
  • Try to create an article content. The text field widget will be rendered 4 times.

Proposed resolution

  • Provide an option to render only one widget in form, in the 'Manage form display' settings of the field (Current name: Show add more button)
  • If this option is selected, only one widget will be rendered in the form along with an 'Add another item' button to add the remaining ones.


Remaining tasks

  • Review
  • Commit

User interface changes

A new checkbox 'Show add more button' in the widget settings of fields with limited cardinality (>1) that provides 'Add another item' button instead of rendering the maximum number of widgets.

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

N/A

Feature request
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated 5 days ago

Created by

🇨🇭Switzerland burki

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇬🇧United Kingdom very_random_man

    This works for me on 9.5. :-)

  • 🇦🇺Australia dpi Perth, Australia

    Seems to me like there might be a lot of crossover between this and 🐛 Fields with unlimited cardinality show 1 extra input field Needs work

    Maybe both should be triaged into a _Optimising add more button behavior_ issue

  • 🇩🇪Germany Anybody Porta Westfalica
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    29,682 pass, 9 fail
  • 🇺🇸United States jsutta United States

    Rerolled the patch for Drupal 10.2.0.

  • 🇧🇪Belgium JeroenT 🇧🇪
  • Merge request !6522Resolve #1156338 "Fixed maximum number" → (Open) created by JeroenT
  • Status changed to Needs review 10 months ago
  • 🇧🇪Belgium JeroenT 🇧🇪
  • Pipeline finished with Failed
    10 months ago
    Total: 177s
    #91206
  • 🇩🇪Germany Anybody Porta Westfalica
  • Status changed to Postponed: needs info 10 months ago
  • 🇺🇸United States smustgrave

    Moving to PNMI if anyone can confirm #35 is a duplicate, then this can be closed.

    If not a duplicate it should move to NW for test coverage and issue summary update.

  • Status changed to Needs work 8 months ago
  • 🇮🇩Indonesia el7cosmos 🇮🇩 GMT+7

    This is still missing "Add More" button.

    Also, not a duplicate of related issue.

  • Pipeline finished with Canceled
    8 months ago
    Total: 35s
    #133083
  • Pipeline finished with Failed
    8 months ago
    Total: 556s
    #133084
  • 🇧🇪Belgium p-neyens

    Here a patch for D10.2.5 with a fix for "Warning: Undefined array key "#delta" in Drupal\Core\Field\WidgetBase::addMoreAjax() (regel 340 van /var/www/html/core/lib/Drupal/Core/Field/WidgetBase.php)"

  • Pipeline finished with Failed
    5 months ago
    Total: 966s
    #213397
  • Pipeline finished with Failed
    5 months ago
    Total: 512s
    #213880
  • Pipeline finished with Failed
    4 months ago
    Total: 156s
    #229663
  • Pipeline finished with Success
    4 months ago
    #229668
  • 🇮🇩Indonesia el7cosmos 🇮🇩 GMT+7

    Updated the MR, added a widget option to opt-in

  • Assigned to Akhil Babu
  • 🇮🇳India Akhil Babu Chengannur
  • Pipeline finished with Failed
    3 months ago
    Total: 159s
    #252637
  • Pipeline finished with Failed
    3 months ago
    Total: 157s
    #252654
  • Pipeline finished with Failed
    3 months ago
    Total: 127s
    #252656
  • Pipeline finished with Failed
    3 months ago
    Total: 171s
    #252658
  • Pipeline finished with Success
    3 months ago
    Total: 532s
    #252665
  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇮🇳India Akhil Babu Chengannur

    I have added the tests. Ready for review

  • Status changed to Needs work 3 months ago
  • 🇺🇸United States smustgrave

    Issue summary still incomplete

    Have not reviewed

  • 🇮🇳India Akhil Babu Chengannur
  • 🇮🇳India Akhil Babu Chengannur
  • 🇮🇳India Akhil Babu Chengannur
  • Status changed to Needs review 3 months ago
  • 🇮🇳India Akhil Babu Chengannur

    Updated the IS, Thanks

  • 🇦🇺Australia pameeela

    Gave this a manual test and it looks good. Updated one of the screenshots in the IS which was taken using Gin rather than Claro.

    I think these two tags can now be removed too, I reviewed the IS and made some minor tweaks. This would be good to include as a highlight in whatever minor version it makes it into :)

  • 🇮🇳India Akhil Babu Chengannur

    akhil babu changed the visibility of the branch 1156338-fixed-maximum-number to hidden.

  • 🇮🇳India Akhil Babu Chengannur

    akhil babu changed the visibility of the branch 1156338-fixed-maximum-number to active.

  • 🇮🇳India prashant.c Dharamshala

    This feature would be beneficial as currently, we are using the contributed modules like
    https://www.drupal.org/project/sam or https://www.drupal.org/project/field_widget_add_more to achieve the same.

    I am attaching the before and after screenshots of the manual review on the local Drupal 11 instance.


    However, I have a few points:

    1. Should not the "Show add more button" be enabled by default in the settings rather than explicitly enabling it?
    2. Now because the button is introduced to add the items the blank field should not be displayed by default without clicking the "Add another item" button.
    3. On the "Manage form display" page in the widget settings the checkbox label is "Show add more button" but the label of the button is not "Add more" it is "Add another item", which might be confusing to some users.

    Thanks!

  • 🇦🇺Australia pameeela

    @prashant.c thanks for the review, but note there are already screenshots provided there is no need to add more.

    Should not the "Show add more button" be enabled by default in the settings rather than explicitly enabling it?

    I can see a case for both, as there are definitely situations where you might want the widgets to show. Don't feel strongly either way.

    On the "Manage form display" page in the widget settings the checkbox label is "Show add more button" but the label of the button is not "Add more" it is "Add another item", which might be confusing to some users.

    I agree the wording could be more clear, but I don't think that saying "Show 'Add another item' button" is the solution because that still isn't that clear. "Simple Add More" module does the opposite of what's in place here: it makes the behaviour the default but offers a setting to show all elements with the wording:

    Skip "Simple Add More" simplification (i.e. show all elements, even if empty).

    So I think we can also describe better what the setting does, but I'm struggling with something that is both clear and concise: "Show button to add more values instead of maximum empty fields" (too long) / "Show button to add more values" (short but not as obvious) / "Show maximum allowed values even if empty" (not that clear?)

    Now because the button is introduced to add the items the blank field should not be displayed by default without clicking the "Add another item" button.

    This is a separate issue - 🐛 Fields with unlimited cardinality show 1 extra input field Needs work

  • 🇮🇳India prashant.c Dharamshala

    Thank you @pameeela for the detailed response. I was not aware of this #2980806: Fields with unlimited cardinality show 1 extra input field.

  • 🇦🇺Australia pameeela

    After thinking more about this I am leaning toward having it be opt out rather than opt in, because I think it would be more common to want it that not. The reasons to not want it IMO would be if the cardinality is 2 or maybe 3, then I think it probably makes sense to just show the widgets. But in those cases, I don't think it's a problem to have it enabled, and folks could opt out.

    The only other consideration is this is a change from the current behaviour that might be unexpected, but I am not sure that is a good reason to have it be opt in.

  • 🇮🇩Indonesia el7cosmos 🇮🇩 GMT+7

    If we want this by default, do we need to update the existing field config?

    It may also make more sense to have "Show all items"/"Show all widgets" instead.

  • 🇦🇺Australia pameeela

    I don't think we would want to update existing config, changing the behaviour after the fact would be pretty confusing. I think it only should be enabled by default for new config.

    So yeah in that case, I think the boolean is off by default, and we can say "Show empty widgets instead of 'Add another item' button" (or something, feedback welcome) for the label. Ideally the label will make it clear what the setting does without being overly long.

    But let's wait a bit and see if there is any other input before making changes.

  • 🇮🇳India prashant.c Dharamshala

    I do not think "Show all items"/"Show all widgets" will make sense because we are not showing all the items at one go, we are providing a way to add another/more item (which is one at a time). So in my opinion "Add another item" is concise and clear to every type of user (technical/non-technical).

    Regarding the default enabling option, we may wait for feedback. :)

  • Status changed to Needs work 2 months ago
  • 🇺🇸United States smustgrave

    Will need some kind of update path for existing sites. If the setting is unchecked add_more: false should be in the config currently it's empty.

Production build 0.71.5 2024