diff --git a/assets/js/src/form_editor/form_editor.js b/assets/js/src/form_editor/form_editor.js index 074145d794..2a85cefafb 100644 --- a/assets/js/src/form_editor/form_editor.js +++ b/assets/js/src/form_editor/form_editor.js @@ -618,16 +618,27 @@ var WysijaForm = { return encodeURI(str).replace(/[!'()*]/g, escape); } }, - updateBlock: function(data) { + updateBlock: function(field) { var hasUpdated = false; WysijaForm.getBlocks().each(function(b) { - if(b.block.getData().id == data.id) { + if(b.block.getData().id === field.id) { hasUpdated = true; - b.block.redraw(data); + b.block.redraw(field); } }); return hasUpdated; + }, + removeBlock: function(field, callback) { + var hasRemoved = false; + WysijaForm.getBlocks().each(function(b) { + if(b.block.getData().id === field.id) { + hasRemoved = true; + b.block.removeBlock(callback); + } + }); + + return hasRemoved; } }; @@ -836,10 +847,6 @@ WysijaForm.Block = Class.create({ Effect.Fade(this.element.identify(), { duration: 0.2, afterFinish: function(effect) { - if(effect.element.next('.mailpoet_form_block') !== undefined && callback !== false) { - // show controls of next block to allow mass delete - WysijaForm.get(effect.element.next('.mailpoet_form_block')).block.showControls(); - } // remove placeholder if(effect.element.previous('.block_placeholder') !== undefined) { effect.element.previous('.block_placeholder').remove(); diff --git a/lib/Router/CustomFields.php b/lib/Router/CustomFields.php index 92aa693f58..faa7e3ebeb 100644 --- a/lib/Router/CustomFields.php +++ b/lib/Router/CustomFields.php @@ -18,15 +18,19 @@ class CustomFields { } function delete($id) { - $result = false; - $custom_field = CustomField::findOne($id); - if($custom_field !== false) { + if($custom_field === false or !$custom_field->id()) { + wp_send_json(array( + 'result' => false + )); + } else { $custom_field->delete(); - $result = true; - } - wp_send_json($result); + wp_send_json(array( + 'result' => true, + 'field' => $custom_field->asArray() + )); + } } function save($data = array()) { diff --git a/views/form/editor.html b/views/form/editor.html index f0e9ba2005..4686e62222 100644 --- a/views/form/editor.html +++ b/views/form/editor.html @@ -547,9 +547,16 @@ endpoint: 'customFields', action: 'delete', data: id - }).done(function(result) { - if(result === true) { + }).done(function(response) { + if(response.result === true) { item.remove(); + + if(response.field !== undefined) { + WysijaForm.removeBlock(response.field, function() { + mailpoet_form_save(false); + }); + } + mailpoet_form_fields(); MailPoet.Notice.success( "<%= __('Removed custom field “"+name+"“') %>"