Update MArvinJS asset on result text cancel

This commit is contained in:
Anton Ignatov 2019-09-30 16:09:43 +02:00
parent 126c29ab12
commit 859c5931a4
2 changed files with 10 additions and 5 deletions

View file

@ -40,18 +40,18 @@
// Edit result text button behaviour
function applyEditResultTextCallback() {
$('.edit-result-text').on('ajax:success', function(e, data) {
$('.edit-result-text').off().on('ajax:success', function(e, data) {
var $result = $(this).closest('.result');
var $form = $(data.html);
var $prevResult = $result;
$result.after($form);
$result.remove();
$prevResult.hide();
formAjaxResultText($form);
formAjaxResultText($form, $prevResult);
// Cancel button
$form.find('.cancel-edit').click(function() {
$form.after($prevResult);
$prevResult.show();
$form.remove();
applyEditResultTextCallback();
TinyMCE.destroyAll();
@ -64,9 +64,10 @@
}
// Apply ajax callback to form
function formAjaxResultText($form) {
function formAjaxResultText($form, $prevResult) {
$form.on('ajax:success', function(e, data) {
var newResult;
if ($prevResult) $prevResult.remove();
$form.after(data.html);
newResult = $form.next();
initFormSubmitLinks(newResult);

View file

@ -310,6 +310,10 @@
if (imageContainer === undefined) {
createImageHiddenField();
}
// Small fix for ResultText when you cancel after change MarvinJS
if (imageContainer === undefined) return [];
imageContainer.value = JSON.stringify(images);
return JSON.stringify(images);
}