grav-plugin-admin: Unset Media doesn't work

Hi, it appears that the “unset” media button (the cross icon when you hover over a preview file) doesn’t seem to work.

Setup :

  • Grav install: Grav v1.4.3 & Grav Admin Panel v1.7.4
  • Have a page with several image file fields with multiple attribute set to false
  • Add a image for each file field
  • Save the page (It should be all good up to here)

My .yaml file :

header.custom.image1:
    type: file
    label: "Image 1"
    filesize: 3
    destination: 'self@'
    accept:
        - image/*

header.custom.image2:
    type: file
    label: "Image 2"
    filesize: 3
    destination: 'self@'
    accept:
        - image/*

Problem 1 :

  • Unset one of the images using the cross icon when you hover the preview
  • Notice that the drag & drop zone doesn’t display any message now
  • Try to upload a new file. You will get the error popin You can not upload any more files.

Problem 2 :

  • Unset one of the images using the cross icon when you hover the preview
  • Notice that the dropdown zone doesn’t display any message now
  • Save the page Now you should end up with all image file fields, filled with the same image ! (the image is the first filled image field)

@lepascal posted an exemple of this issue here with a repeater field, but it’s also true with only 2 image fields.

Temporary Solution 1 - NOT WORKING I wanted to set my image file fields as required using the validate.required attribute in order to prevent saving the page if an image field is empty, but this is not working. This is a know bug and I added a comment here

Temporary Solution 2 - working, but not ideal As the problem seems to come from the cross icon only, I got rid of it. In my theme, I added this piece of code into my custom.js file :

$(function(){
    // Hide existing unset buttons
    $('.dz-unset').css('display', 'none');

    // Prevent click on unset buttons
    // In case the button was added dynamically
    // or the display attribute was overridden
    $(document).on('click', '.dz-unset', function (e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        alert('Sorry, the unset button is not working');
    });
});

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (17 by maintainers)

Commits related to this issue

Most upvoted comments

This is now solved, I merged @rotanadan PR.

Thanks all for the help and patience.