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

  1. Enable media_library module
  2. Add a media field to basic page content type
  3. Create a basic page
  4. Click on Add Media to the field you created
  5. Add a file on "Choose File"
  6. Save
  7. Add another file on "Choose File"
  8. The message should appear
  9. Deselect one of the media items previously uploaded
  10. 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

Issue fork drupal-3567770

Command icon 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:

Comments

julio_retkwa created an issue. See original summary.

julio_retkwa’s picture

Issue summary: View changes
julio_retkwa’s picture

Issue summary: View changes
julio_retkwa’s picture

StatusFileSize
new2.02 KB

julio_retkwa changed the visibility of the branch 3567770-media-library-message to hidden.

cilefen’s picture

Status: Active » Needs work
Issue tags: +Needs merge request

julio_retkwa’s picture

Status: Needs work » Needs review
julio_retkwa’s picture

julio_retkwa’s picture

Assigned: julio_retkwa » Unassigned

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Issue tags: -Needs review

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative
StatusFileSize
new172.46 KB

Followed the steps to reproduce

bug

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

  • lauriii committed e374c30d on main
    fix: #3567770 Media Library message persists after deselecting items to...

  • lauriii committed c27ae7eb on 11.x
    fix: #3567770 Media Library message persists after deselecting items to...

  • lauriii committed 9c11dbc8 on 11.3.x
    fix: #3567770 Media Library message persists after deselecting items to...

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed! Thank you @julio_retkwa and @smustgrave

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.