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 2 March 2023, almost 2 years ago

Hi

I'm pretty sure, I missed something, but actually I didn't found any solution or module for my requirement. So I end up here with a feature request.

I would love if I can limit the number of field values to let's say 15, but instead of showing all 15 field widgets in the form, I would like to show just one or two and use the «add more» button to add more field values (like when I allow «unlimited» number of values).

Does anybody know a way to realize this? I think this would be a very helpful feature.

I think the cardinality-selectbox could stay as is, but there could be an additional selectbox with two values like «show fields for all values» and «add more fields as needed».

Any hints about how this could be done are welcome. If I know how to do it, I could write a module and contribute it.

Thanks
Burki

Feature request
Status

Needs work

Version

10.1

Component
Field 

Last updated about 9 hours ago

Created by

🇨🇭Switzerland burki

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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 about 1 year ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year 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 11 months ago
  • 🇧🇪Belgium JeroenT 🇧🇪
  • Pipeline finished with Failed
    11 months ago
    Total: 177s
    #91206
  • 🇩🇪Germany Anybody Porta Westfalica
  • Status changed to Postponed: needs info 11 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 10 months ago
  • 🇮🇩Indonesia el7cosmos 🇮🇩 GMT+7

    This is still missing "Add More" button.

    Also, not a duplicate of related issue.

  • Pipeline finished with Canceled
    10 months ago
    Total: 35s
    #133083
  • Pipeline finished with Failed
    10 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
    6 months ago
    Total: 966s
    #213397
  • Pipeline finished with Failed
    6 months ago
    Total: 512s
    #213880
  • Pipeline finished with Failed
    6 months ago
    Total: 156s
    #229663
  • Pipeline finished with Success
    6 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
    5 months ago
    Total: 159s
    #252637
  • Pipeline finished with Failed
    5 months ago
    Total: 157s
    #252654
  • Pipeline finished with Failed
    5 months ago
    Total: 127s
    #252656
  • Pipeline finished with Failed
    5 months ago
    Total: 171s
    #252658
  • Pipeline finished with Success
    5 months ago
    Total: 532s
    #252665
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • 🇮🇳India Akhil Babu Chengannur

    I have added the tests. Ready for review

  • Status changed to Needs work 5 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 5 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 4 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.

  • First commit to issue fork.
  • Merge request !10400Resolve #1156338 "Fixed maximum number 1" → (Closed) created by Unnamed author
  • Pipeline finished with Failed
    about 1 month ago
    Total: 180s
    #354634
  • Pipeline finished with Failed
    about 1 month ago
    Total: 298s
    #354653
  • Pipeline finished with Failed
    about 1 month ago
    Total: 1056s
    #354663
  • Pipeline finished with Failed
    about 1 month ago
    Total: 216s
    #354675
  • Pipeline finished with Failed
    about 1 month ago
    Total: 732s
    #354907
  • 🇮🇳India ramprassad

    @smustgrave I have created a new MR (10400) with an update hook in file.install which updates the add_more:false in the form display config for the applicable bundles where these multivalued fields are available. This includes the changes in the previous MR.
    My opinion would be to have add_more:true, to have this feature enabled by default to give a good user experience to content authors. Please review and suggest.

  • 🇺🇸United States smustgrave

    Please add to an existing MR vs starting a new when the current is pointing to the correct brandh

  • Pipeline finished with Failed
    about 1 month ago
    Total: 846s
    #356029
  • Pipeline finished with Success
    about 1 month ago
    Total: 556s
    #356054
  • 🇮🇳India ramprassad

    ramprassad changed the visibility of the branch 1156338-fixed-maximum-number-1 to hidden.

  • 🇮🇳India ramprassad

    @smustgrave I have updated the current MR and closed the other one. Please check

  • 🇮🇳India sagarmohite0031

    Hello,
    Tested and verified on Drupal 11,
    MR applied successfully
    Attaching before and after screenshot

  • Pipeline finished with Canceled
    about 1 month ago
    Total: 1309s
    #360899
  • Pipeline finished with Success
    about 1 month ago
    Total: 691s
    #360925
  • The issue is still not fixed for me i had to manually check the 'Show add more button' then the add more button is appearing.

  • 🇮🇳India ramprassad

    @saurav-drupal-dev Yes this is how its supposed to be for now. By default "Show add more" button will not be checked and we are waiting on the community's decision(pls see #56 to #60). If it has to be enabled, I can update the config as well.

  • 🇺🇸United States smustgrave

    Left comments on MR.

  • Pipeline finished with Canceled
    8 days ago
    #383300
  • Pipeline finished with Failed
    8 days ago
    Total: 162s
    #383302
  • Pipeline finished with Failed
    8 days ago
    #383304
  • Pipeline finished with Success
    8 days ago
    Total: 1254s
    #383305
  • Pipeline finished with Success
    8 days ago
    Total: 3004s
    #383467
  • Pipeline finished with Failed
    7 days ago
    Total: 200s
    #384556
  • Pipeline finished with Failed
    7 days ago
    Total: 856s
    #384559
  • Pipeline finished with Success
    7 days ago
    Total: 2239s
    #384583
  • 🇮🇳India ramprassad

    @smustgrave, I have addressed the comments on the MR, please check.

  • Pipeline finished with Success
    6 days ago
    Total: 2739s
    #384640
Production build 0.71.5 2024