Skip to content

Commit

Permalink
Fixed unset so it only targets nearest hidden field, not all hidden f…
Browse files Browse the repository at this point in the history
…ields
  • Loading branch information
hdwebpros committed Dec 14, 2018
1 parent 8cd2e88 commit 54d800a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions themes/grav/app/pages/page/unset.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import $ from 'jquery';

$(document).on('click', '.dz-unset', function() {
$(this).closest('.dz-image-preview').remove();
const file_upload = $('.files-upload');
const unset_image = $(this).closest('.dz-image-preview').find('[data-dz-name]').text().trim();
const images = JSON.parse(file_upload.find('input[data-grav-field="hidden"]').val()) || {};
let image_array = {};
$.each(images, function(ind, obj) {
if (!ind.endsWith(unset_image)) {
image_array[ind] = obj;
}
});
file_upload.find('input[data-grav-field="hidden"]').val(JSON.stringify(image_array));
const file_upload = $(this).closest('.files-upload');
const next_closest = $(this).closest('.dz-image-preview');
const hidden_field = 'input[data-grav-field="hidden"]';
if (next_closest.length) {
const unset_image = next_closest.find('[data-dz-name]').text().trim();
const images = JSON.parse(file_upload.find(hidden_field).val()) || null;
let image_array = {};
$.each(images, function(ind, obj) {
if (!ind.endsWith(unset_image)) {
image_array[ind] = obj;
}
});
file_upload.find(hidden_field).val(JSON.stringify(image_array));
next_closest.remove();
}
});

0 comments on commit 54d800a

Please sign in to comment.