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
- Install Drupal
- Activate core modules Media and Media Library
- Create custom content type and add a media field with the media library widget
- Go to add a content of the custom content type
- Click on the "Add media" button
- 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.
Proposed resolution
Make the 'Insert selected' of zero items behave similar to selecting too many items. Ensure validation messages are only shown as a result of clicking 'Insert selected'.
Remaining tasks
Review
User interface changes
The error message is only shown when the 'Insert selected' button is clicked, not when the dialog is closed without clicking it (and then subsequently reopening the dialog).
Introduced terminology
None
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | updated-screenshot.png | 109.63 KB | scott_euser |
| #13 | error_message.mp4 | 420.47 KB | rkoller |
| #13 | with_media_items.jpg | 88.7 KB | rkoller |
| #13 | inline.jpg | 75.31 KB | rkoller |
| #10 | no-item-selected.png | 121.51 KB | scott_euser |
Issue fork drupal-3277735
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
Comment #5
scott_euser commentedI wonder if the modal should actually have a Cancel button to avoid this.
I also noticed that if you do this:
Then when inserting new:
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:
(on decision, update issue summary with standard template + proposed solution)
Comment #7
anmolgoyal74 commentedWe are also facing the same issue.
We can disable the insert selected button until the media is selected.
The user can use the cross "X" button to close the modal if needed,
Comment #8
quietone commentedThere isn't a "Needs UX review" tag, so changing tag.
This was reported on Drupal 9, which is no longer supported. Is this happening on currently supported versions of Drupal?
Comment #9
scott_euser commentedYes this is still an issue; insert selected can still be clicked on main branch without any selections (and it still also causes what I noted in #5). I removed the specific reference to Drupal 9
Comment #10
scott_euser commentedThe inline validation now shows up in the exact same was as selecting too many items (e.g. if 2 are allowed and you selected 3):
I think it makes sense for the message to be "No items selected. Consider closing the dialog instead." instead of just "No items selected." given that the intent of the user could be to close the dialog if they are used to it behaving like that despite the button label. No harm perhaps?
The validate method is called via Views with a method_exists() wrapper on all field handlers, so removing it prevents the unconditional call, and moves it to a conditional call to match the too many items selected behaviour; ie only triggered when clicking 'Insert selected' but not triggered when clicking the close dialog X button.
Comment #12
scott_euser commentedTests now passing (including new coverage) + updated the description to use the standard issue summary template.
Comment #13
rkollerUsability review
We discussed this issue at #3589097: Drupal Usability Meeting 2026-05-15. The link to the recording: https://www.youtube.com/watch?v=INHnpnxH7CI&t=1391s . The attendees at the usability meeting were @benjifisher, @rkoller, @simohell, @the_g_bomb, and @worldlinemine.
Thanks for working on the issue @scott_euser. In general the group was in line with the proposed resolution to not close the dialog modal and in consequence to not change the context in case no image was selected when pressing/clicking the
Insert selectedbutton. It has to be noted that we haven't had enough time left in yesterday's meeting, so we will most likely revisit and finish the review next week if time permits. For now a brief summary of our explorations about the current state of MR15604:No media available.message from the media library viewwhile with media items available, the error message only spans across the left half of the dialog modal
No items selected. Consider closing the dialog instead.about how to resolve the error is sort of misleading. The error does not block the interaction within the dialog that would require the closing of the dialog modal and or the reload of the page - the user has simply to select a certain number of media items depending on the field settings and/or upload media items in the first place.Insert selectedbutton the focus jumps to the filter field, no matter if there are media items to filter or if no media items are available and the list is empty. Problem with that, the filter section is the only part of the form that can't directly change what is getting selected.The sole recommendation the group agreed on during yesterday's meeting, in case the people working on the issue don't consider it already out of scope, is moving the element wrapping the error message one level up in the DOM so it is placed right before in order, on the same level, as the form element. The visual position of the error message wouldn't change, it would be still positioned between the grid/table toggle switch and the "no media available" message or the block of media item cards if media items are available - the only difference, the error message would be now spanning across the entire dialog modal and would also not be inline with the "no media available" message.
In regard to the element getting into focus after pressing the
Insert selectedbutton, one idea that was raised, instead of getting the filter field into focus, put the focus onto theChoose filebutton. But that most likely would be the proposed resolution for a potential follow up? Or would be extending the scope for this issue, and fixing the focus problem right away, be considered reasonable to the folks working on this issue?In regard to the micro copy used on the error message, we haven't had the time left for word smithing yesterday. We will get to that as soon as we will continue our discussion.
I'll keep the "Needs usability review" tag on the issue for now, until we've revisited it for a second time and finish our discussion.
If you want more feedback from the usability team, a good way to reach out is in the #ux channel in Slack.
Comment #14
scott_euser commentedThanks for the feedback! Moving it up a level would not work as it would change its location to above the choose file, so instead I added css so the flexbox of the messages list spans the full width:
I changed the message to "No items selected." removing the bit about closing the dialog.
I am not sure about increasing the scope to cover focus changes either, so I left that untouched.
Ready for review again I think.
Comment #15
smustgrave commented@rkoller if you're good with the changes we can proceed to review
Comment #16
rkollerUsability review
We discussed this issue for a second time at #3590325: Drupal Usability Meeting 2026-05-22. The link to the recording: https://www.youtube.com/watch?v=5tmSB4zZBfo&t=12s . The attendees at the usability meeting were @benjifisher, @rkoller, and @simohell.
Thanks @scott_euser for applying our suggestions from last week's meeting! The overall behavior of the error message looks good now. fab! So we've focused our discussions during the second meeting onto the micro copy of the error message.
The proposal to go with just
No items selected, dropping the second sentence withConsider closing the dialog instead, looked like an interesting approach at first. We've asked ourselves, what are the scenarios a user could run into that kind of error message?Insert selectedInsert selectedbutton insteadThe group had a consensus, in case scenario 1 applies people are in control and know the context they are currently in - they have the situational awareness. In that case the
No items selectedcould be considered sufficient and by adding any additional instructions how to add media items would make the error message overly verbose. The only problemNo items selecteddoes not cover for scenario 2. We would suggest re-adding a second sentence. Instead of proposing to close the dialog withConsider closing the dialog instead), it might be the better choice to slightly rephrase the sentence by outlining scenario 2 and to provide some sort of guidance to the user how to close the dialog modal withIf you want to close the dialog, use the ESC key or the X icon.. So our suggestion for the error message would be:If applicable, instead of simply write
Xlike in the aforementioned proposal, it might be considered using the actual X icon used on dialog modal inline in the error message - to illustrate the icon the user has to press/click (and for screenreader users use theClosetitle, same as on the icon on the dialog modal).If you want more feedback from the usability team, a good way to reach out is in the #ux channel in Slack.
Comment #17
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #18
smustgrave commentedComment #19
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #20
smustgrave commentedComment #21
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.