diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 09621b2..e329ea7 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -490,8 +490,8 @@ else if (this.progress.type === 'throbber') { // Reattach behaviors, if they were detached in beforeSerialize(). The // attachBehaviors() called on the new content from processing the response // commands is not sufficient, because behaviors from the entire form need - // to be reattached. - if (this.$form) { + // to be reattached, if it's still part of the document. + if (this.form && $.contains(document, this.form)) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -543,8 +543,9 @@ else if (type === 'fade') { $(this.wrapper).show(); // Re-enable the element. $(this.element).removeClass('progress-disabled').prop('disabled', false); - // Reattach behaviors, if they were detached in beforeSerialize(). - if (this.$form) { + // Reattach behaviors, if they were detached in beforeSerialize(), and the + // form is still part of the document. + if (this.form && $.contains(document, this.form)) { var settings = response.settings || this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); }