diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 6248e46efe..1cdbfc8d6b 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -706,7 +706,7 @@ // when there is a form such that this.$form.ajaxSubmit() is used instead of // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize() // isn't called, but don't rely on that: explicitly check this.$form. - if (this.$form) { + if (this.$form && $.contains(document, this.$form.get(0))) { const settings = this.settings || drupalSettings; Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); } @@ -885,7 +885,7 @@ // 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) { + if (this.$form && $.contains(document, this.$form.get(0))) { const settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -955,8 +955,9 @@ $(this.wrapper).show(); // Re-enable the element. $(this.element).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.get(0))) { const settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 5ea52425be..40bb135aff 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -325,7 +325,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr }; Drupal.Ajax.prototype.beforeSerialize = function (element, options) { - if (this.$form) { + if (this.$form && $.contains(document, this.$form.get(0))) { var settings = this.settings || drupalSettings; Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); } @@ -423,7 +423,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr } } - if (this.$form) { + if (this.$form && $.contains(document, this.$form.get(0))) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -465,7 +465,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr $(this.element).prop('disabled', false); - if (this.$form) { + if (this.$form && $.contains(document, this.$form.get(0))) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php index e48487a6ed..44042cdf9c 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php @@ -71,6 +71,21 @@ public function testFilterCriteriaDialog() { $this->drupalGet('admin/structure/views/view/who_s_online'); $page = $this->getSession()->getPage(); $this->assertNotNull($page->findLink('User: Last access (>= -15 minutes)')); + + // Add group again to test drag-n-drop. + $create_new_filter_group = $page->findById('views-add-group-link'); + $this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.'); + $create_new_filter_group->click(); + $assert_session->assertWaitOnAjaxRequest(); + + // Validate dragging works correctly and the new group will contain the new + // filter. + $dragged = $page->find('css', ".tabledrag-handle"); + $target = $page->find('css', '.filter-group-operator-row'); + $dragged->dragTo($target); + + $remove_link = $page->findLink('Remove group'); + $this->assertFalse($remove_link->isVisible(), 'Remove group should be invisible after drag.'); } }