unset.js 621 B

123456789101112131415
  1. import $ from 'jquery';
  2. $(document).on('click', '.dz-unset', function() {
  3. $(this).closest('.dz-image-preview').remove();
  4. const file_upload = $('.files-upload');
  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. });