unset.js 638 B

123456789101112131415161718
  1. import $ from 'jquery';
  2. $(document).on('click', '.dz-unset', function() {
  3. const file_upload = $(this).closest('.files-upload');
  4. $(this).closest('.dz-image-preview').remove();
  5. const unset_image = $(this).closest('.dz-image-preview').find('[data-dz-name]').text().trim();
  6. const images = JSON.parse(file_upload.find('input[data-grav-field="hidden"]').val()) || {};
  7. let image_array = {};
  8. $.each(images, function(ind, obj) {
  9. if (!ind.endsWith(unset_image)) {
  10. image_array[ind] = obj;
  11. }
  12. });
  13. file_upload.find('input[data-grav-field="hidden"]').val(JSON.stringify(image_array));
  14. });