diff -u b/core/misc/ajax.es6.js b/core/misc/ajax.es6.js --- b/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 && $.contains(document, this.$form.get(0))) { + if (this.$form) { const settings = this.settings || drupalSettings; Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); } @@ -774,7 +774,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 && $.contains(document, this.$form.get(0))) { + if (this.$form) { const settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -955,9 +955,8 @@ $(this.wrapper).show(); // Re-enable the element. $(this.element).prop('disabled', false); - // 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))) { + // Reattach behaviors, if they were detached in beforeSerialize(). + if (this.$form) { const settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -1021,7 +1020,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); } @@ -1089,8 +1088,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 -u b/core/misc/ajax.js b/core/misc/ajax.js --- b/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -325,7 +325,7 @@ }; Drupal.Ajax.prototype.beforeSerialize = function (element, options) { - if (this.$form && $.contains(document, this.$form.get(0))) { + if (this.$form) { var settings = this.settings || drupalSettings; Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); } @@ -339,7 +339,7 @@ }; 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 @@ } } - if (this.$form && $.contains(document, this.$form.get(0))) { + if (this.$form) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -451,7 +451,7 @@ } } - 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 @@ $(this.element).prop('disabled', false); - if (this.$form && $.contains(document, this.$form.get(0))) { + if (this.$form) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -493,7 +493,7 @@ $(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 -u b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php --- b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php @@ -42,13 +42,7 @@ $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); - // Use the 'And/Or Rearrange' link for fields to open a dialog. - $dropbutton = $page->find('css', '.views-ui-display-tab-bucket.filter .dropbutton-toggle button'); - $dropbutton->click(); - $add_link = $page->findById('views-rearrange-filter'); - $this->assertTrue($add_link->isVisible(), 'And/Or Rearrange button found.'); - $add_link->click(); - $assert_session->assertWaitOnAjaxRequest(); + $this->openFilterDialog(); // Add a new filter group. $create_new_filter_group = $page->findById('views-add-group-link'); @@ -73,7 +67,10 @@ $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->openFilterDialog(); + + $this->assertSession()->waitForLink('Create new filter group', 20000); + $create_new_filter_group = $page->findLink('Create new filter group'); $this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.'); $create_new_filter_group->click(); $assert_session->assertWaitOnAjaxRequest(); @@ -90,2 +87,16 @@ + /** + * Use the 'And/Or Rearrange' link for fields to open a dialog. + */ + protected function openFilterDialog() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + $dropbutton = $page->find('css', '.views-ui-display-tab-bucket.filter .dropbutton-toggle button'); + $dropbutton->click(); + $add_link = $page->findById('views-rearrange-filter'); + $this->assertTrue($add_link->isVisible(), 'And/Or Rearrange button found.'); + $add_link->click(); + $assert_session->assertWaitOnAjaxRequest(); + } + }