diff --git a/misc/ajax.js b/misc/ajax.js index bb4a6e1..1cb6253 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -432,8 +432,8 @@ Drupal.ajax.prototype.success = function (response, status) { // 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.get(0))) { var settings = this.settings || Drupal.settings; Drupal.attachBehaviors(this.form, settings); } @@ -488,8 +488,9 @@ Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { $(this.wrapper).show(); // Re-enable the element. $(this.element).removeClass('progress-disabled').removeAttr('disabled'); - // 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.get(0))) { var settings = this.settings || Drupal.settings; Drupal.attachBehaviors(this.form, settings); }