diff --git a/core/misc/ajax.js b/core/misc/ajax.js index fefe9f3..c3d416c 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -708,7 +708,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))) { var settings = this.settings || drupalSettings; Drupal.detachBehaviors(this.$form.get(0), settings, 'serialize'); } @@ -887,7 +887,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))) { var settings = this.settings || drupalSettings; Drupal.attachBehaviors(this.$form.get(0), settings); } @@ -957,8 +957,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))) { 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 new file mode 100644 index 0000000..ef76540 --- /dev/null +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php @@ -0,0 +1,87 @@ +drupalCreateUser([ + 'administer site configuration', + 'administer views', + 'administer nodes', + 'access content overview', + ]); + + // Disable automatic live preview to make the sequence of calls clearer. + \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save(); + $this->drupalLogin($admin_user); + } + + /** + * Tests dialog for filter criteria. + */ + public function testFilterCriteriaDialog() { + $this->drupalGet('admin/structure/views/view/content_recent'); + $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(); + + // Add a new filter group. + $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(); + + // Assert the existence of the new filter group by checking the remove group + // link. + $remove_link = $page->findLink('Remove group'); + $this->assertTrue($remove_link->isVisible(), 'New group found.'); + + // Remove the group again and assert the group is not present anymore. + $remove_link->click(); + $assert_session->assertWaitOnAjaxRequest(); + $remove_link = $page->findLink('Remove group'); + $this->assertEmpty($remove_link, 'Remove button not available'); + + // 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 to an invalid location doesn't work. + $dragged = $page->find('css', ".tabledrag-handle"); + $target = $page->find('css', '.filter-group-operator-row'); + $dragged->dragTo($target); + + // $this->createScreenshot('/Library/Webserver/Documents/result.png'); + + $remove_link = $page->findLink('Remove group'); + $this->assertFalse($remove_link->isVisible(), 'Remove group should be invisible after drag.'); + + } +}