Media library field modal should not close after clicking the "Insert selected" buttom if there is no image selected

Created on 28 April 2022, almost 3 years ago
Updated 23 August 2024, 8 months ago

Problem/Motivation

When you click on the "Insert selected" button on the media library widget in a content type without uploading or selecting any elements on the library the modal closes without warning or showing any errors, but when you go back to "Add media" again, the modal opens and then you see the "No items selected" error. This feels off. If you are going to show an error message it should be displayed in the message area of the content type form right after closing the modal or prevent the modal from closing and show the error right there, you should not have to reopen the modal to see the error message.

Steps to reproduce

1 - Install Drupal 9
2 - Activate core modules Media and Media Library
3 - Create custom content type and add a media field with the media library widget
4 - Go to add a content of the custom content type
5 - Click on the "Add media" button
6 - Click on the "Insert selected" button without uploading or selecting any element on the library

You will notice that the modal closes and nothing else happens, but when you go to "Add media" again you'll see the error message when the modal opens.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated 23 minutes ago

Created by

πŸ‡¨πŸ‡ΊCuba ramonma1989

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

Comments & Activities

Not all content is available!

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

  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    I wonder if the modal should actually have a Cancel button to avoid this.

    I also noticed that if you do this:

    1. Create node bundle with required media field, e.g. 'Featured image'

    Then when inserting new:

    1. Open media library for 'Featured image'
    2. Change mind and decide to do later, so click 'Insert selected' to close
    3. Add title, body, etc
    4. Select a 'Featured image' this time from Media Library
    5. Save node

    Then message is shown 'No items selected' (as well as successfully creating the Node) as it seems the media library 'cancel' did not trigger a form refresh, so the 'No items selected' stayed in the messenger queue even though a Media Library selection was actually made in step 4 above.

    So I think possible solutions here:

    1. Ensure that an effective 'Cancel' still triggers form refresh so 'No items selected' message is shown at appropriate time
    2. Avoid showing 'No items selected' validation until full node save; ie, skip validation in the subform and only apply at form level
    3. Provide a Cancel button

    (on decision, update issue summary with standard template + proposed solution)

Production build 0.71.5 2024