Problem/Motivation
When a user selects more media items than allowed by a field's cardinality limit and clicks "Insert selected", an error message is displayed: "There are currently X items selected. The maximum number of items for the field is Y. Remove Z items from the selection."
However, when the user deselects items to get back within the allowed limit, this message remains visible until they click "Insert selected" again. This creates a confusing UX where the user has already corrected the issue but still sees the error.
Steps to reproduce
- Enable media_library module
- Add a media field to basic page content type
- Create a basic page
- Click on Add Media to the field you created
- Add a file on "Choose File"
- Save
- Add another file on "Choose File"
- The message should appear
- Deselect one of the media items previously uploaded
- Notice the message is still visible
Proposed resolution
Clear the #media-library-messages container in the checkEnabled() JavaScript function in media_library.ui.js when the selection count returns to within the allowed limit.
Remaining tasks
- Review
- Test
User interface changes
Error/warning messages in the media library modal are now automatically cleared when the user deselects items to return within the field's cardinality limit.
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
None
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | Screenshot 2026-02-01 at 6.32.54 PM.png | 172.46 KB | smustgrave |
| #4 | 3567770-4.patch | 2.02 KB | julio_retkwa |
Issue fork drupal-3567770
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3567770-media-library-message
changes, plain diff MR !14359
Comments
Comment #2
julio_retkwaComment #3
julio_retkwaComment #4
julio_retkwaComment #6
cilefen commentedComment #8
julio_retkwaComment #9
julio_retkwaComment #10
julio_retkwaComment #12
quietone commentedChanging tags per Issue tags field and Issue tags -- special tags
Comment #14
smustgrave commentedFollowed the steps to reproduce
Can confirm the bug and that the MR does fix the issue.
Rebased the MR and ran test-only https://git.drupalcode.org/issue/drupal-3567770/-/jobs/8316055 and it shows the coverage.
LGTM
Comment #19
lauriiiCommitted! Thank you @julio_retkwa and @smustgrave