core/modules/edit/js/util.js | 11 +++++++++++ core/modules/edit/js/views/EditorView.js | 12 ++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/modules/edit/js/util.js b/core/modules/edit/js/util.js index 6ab6b27..deb1e89 100644 --- a/core/modules/edit/js/util.js +++ b/core/modules/edit/js/util.js @@ -70,6 +70,7 @@ Drupal.edit.util.form = { // Implement a scoped editFieldForm AJAX command: calls the callback. formLoaderAjax.commands.editFieldForm = function (ajax, response, status) { callback(response.data, ajax); + $el.off('edit-internal.edit'); }; // This will ensure our scoped editFieldForm AJAX command gets called. $el.trigger('edit-internal.edit'); @@ -108,6 +109,16 @@ Drupal.edit.util.form = { }; return formSaveAjax; + }, + + /** + * Cleans up the Drupal.ajax instance that is used to save the form. + * + * @param Drupal.ajax ajax + * A Drupal.ajax that was returned by Drupal.edit.form.ajaxifySaving(). + */ + unajaxifySaving: function (ajax) { + $(ajax.element).off('click.edit'); } }; diff --git a/core/modules/edit/js/views/EditorView.js b/core/modules/edit/js/views/EditorView.js index fa71ada..228fe78 100644 --- a/core/modules/edit/js/views/EditorView.js +++ b/core/modules/edit/js/views/EditorView.js @@ -196,6 +196,8 @@ Drupal.edit.EditorView = Backbone.View.extend({ // for an entity that this needs to happen: precisely now! reset: !this.fieldModel.get('entity').get('inTempStore') }; + + var self = this; Drupal.edit.util.form.load(formOptions, function (form, ajax) { // Create a backstage area for storing forms that are hidden from view // (hence "backstage" — since the editing doesn't happen in the form, it @@ -209,14 +211,16 @@ Drupal.edit.EditorView = Backbone.View.extend({ // forms.) $('#edit_backstage form').prop('novalidate', true); var $submit = $('#edit_backstage form .edit-form-submit'); - var formSaveAjax = Drupal.edit.util.form.ajaxifySaving(formOptions, $submit); + self.formSaveAjax = Drupal.edit.util.form.ajaxifySaving(formOptions, $submit); function removeHiddenForm () { + Drupal.edit.util.form.unajaxifySaving(self.formSaveAjax); + delete self.formSaveAjax; $('#edit_backstage').remove(); } // Successfully saved. - formSaveAjax.commands.editFieldFormSaved = function (ajax, response, status) { + self.formSaveAjax.commands.editFieldFormSaved = function (ajax, response, status) { removeHiddenForm(); // First, transition the state to 'saved'. @@ -227,7 +231,7 @@ Drupal.edit.EditorView = Backbone.View.extend({ }; // Unsuccessfully saved; validation errors. - formSaveAjax.commands.editFieldFormValidationErrors = function (ajax, response, status) { + self.formSaveAjax.commands.editFieldFormValidationErrors = function (ajax, response, status) { removeHiddenForm(); editorModel.set('validationErrors', response.data); @@ -239,7 +243,7 @@ Drupal.edit.EditorView = Backbone.View.extend({ // Form API then marks which form items have errors. This is useful for // the form-based in-place editor, but pointless for any other: the form // itself won't be visible at all anyway! So, we just ignore it. - formSaveAjax.commands.editFieldForm = function () {}; + self.formSaveAjax.commands.editFieldForm = function () {}; fillAndSubmitForm(editorModel.get('currentValue')); });