Problem/Motivation
I am running into an issue when adding media into a field that allows only one item. I am adding a block in Layout Builder. The block I am adding has a media field with a limit of one item. However, I can check more than one image on that field by clicking on the image even though the input field is disabled after one image is selected. And I can then insert those two images into the block but I can't save it and I can't remove the images so I have to start over.
I found that the issue is in media_library.click_to_select.js line 14.
$input.prop('checked', !$input.prop('checked')).trigger('change');
Steps to reproduce
Note: Make sure that one of the content types has layout builder enabled.
- Create a "Test" block with a media field
- Set "Allowed number of values" to 1
- Set the "Media type" to Image and save
- Create a new node of the content type that has Layout Builder enabled
- Click "Layout" to add the new block
- Click "Add Media" and select more than one image
You'll notice that you can select more than one image and you can click Insert Selected.
Proposed resolution
Change media_library.click_to_select.js line 14 to:
if (!$input.prop('disabled')) {
$input.prop('checked', !$input.prop('checked')).trigger('change');
}
I also noticed that there is a es6.js version of the file and a similar change would apply there but I am not sure what the criteria is that would allow that file to be used.
Comment | File | Size | Author |
---|---|---|---|
#4 | 3206944-4.patch | 1.08 KB | JurgenR |
Screen Recording 2021-04-02 at 8.48.04 AM.mov | 445.22 KB | bbytyqi |
Issue fork drupal-3206944
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 #3
dstorozhukComment #4
JurgenR CreditAttribution: JurgenR commentedReopening the ticket as the mentioned duplicate is related to the file module.
This ticket is related to the media_library module, which causes the bug in the layout builder.
Sure the problem is similar but the solution seems to be module specific.
I've added a patch based on the proposal of bbytyqi.
Not sure how to test and/or change the es6 file. Help is appreciated.
Comment #5
ironsizide CreditAttribution: ironsizide at Message Agency commentedReporting that the patch works with Drupal 9.5.10 for me.
Comment #6
AnybodyComment #10
dbrowncode CreditAttribution: dbrowncode commentedPushed MR in #9 that works on D10.2.5 for me.
Similar to the previous one, but changed the selector to exclude disabled inputs instead of adding the check after.
Comment #11
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis may have been fixed already in 11.x
If not will need a test case