Issue #1551534 by Lendude, vsujeetkumar, neclimdul, b_sharpe, devert, bcn, henkholtrop, heykarthikwithu, richmac, seanB, casey, mishac, alansaviolobo, idebr, lauriii, dawehner, alexpott, BramDriesen, randell, ilya.no, muka, DamienMcKenna, Dom., dnewkerk, tim-diels, natted, slayne40, Spry_Julia, Jibus, cpliakas, pbouchereau, S3b0uN3t, HongPong, rfbrandsma, grantkruger, sanderwind, borisson_, nerdacus, mglaman, mvwensen, jmickela, droplet: Submit buttons themed as <button> element fail to trigger ajax in Views exposed forms

merge-requests/685/head
effulgentsia 2021-06-30 11:13:20 -07:00
parent 88968d7580
commit 54781848a0
4 changed files with 61 additions and 2 deletions

View File

@ -139,7 +139,10 @@
this.exposedFormAjax = [];
// Exclude the reset buttons so no AJAX behaviors are bound. Many things
// break during the form reset phase if using AJAX.
$('input[type=submit], input[type=image]', this.$exposed_form)
$(
'input[type=submit], button[type=submit], input[type=image]',
this.$exposed_form,
)
.not('[data-drupal-selector=edit-reset]')
.each(function (index) {
const selfSettings = $.extend({}, that.element_settings, {

View File

@ -80,7 +80,7 @@
Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
var that = this;
this.exposedFormAjax = [];
$('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
$('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
var selfSettings = $.extend({}, that.element_settings, {
base: $(this).attr('id'),
element: this

View File

@ -151,4 +151,47 @@ class ExposedFilterAJAXTest extends WebDriverTestBase {
$this->assertStringNotContainsString('Page Two', $html);
}
/**
* Tests exposed filtering via AJAX with a button element.
*/
public function testExposedFilteringWithButtonElement() {
// Install theme to test with template system.
\Drupal::service('theme_installer')->install(['views_test_theme']);
// Make base theme default then test for hook invocations.
$this->config('system.theme')
->set('default', 'views_test_theme')
->save();
$this->drupalGet('admin/content');
$session = $this->getSession();
// Ensure that the Content we're testing for is present.
$html = $session->getPage()->getHtml();
$this->assertStringContainsString('Page One', $html);
$this->assertStringContainsString('Page Two', $html);
$button_tag = $session->getPage()->findButton('edit-submit-content')->getTagName();
// Make sure the submit button has been transformed to a button element.
$this->assertEquals('button', $button_tag);
$drupal_settings = $this->getDrupalSettings();
$ajax_views_before = $drupal_settings['views']['ajaxViews'];
// Search for "Page One".
$this->submitForm(['title' => 'Page One'], t('Filter'));
$this->assertSession()->assertWaitOnAjaxRequest();
// Verify that only the "Page One" Node is present.
$html = $session->getPage()->getHtml();
$this->assertStringContainsString('Page One', $html);
$this->assertStringNotContainsString('Page Two', $html);
$drupal_settings = $this->getDrupalSettings();
$ajax_views_after = $drupal_settings['views']['ajaxViews'];
// Make sure that the views_dom_id didn't change, which would indicate that
// the page reloaded instead of doing an AJAX update.
$this->assertSame($ajax_views_before, $ajax_views_after);
}
}

View File

@ -0,0 +1,13 @@
{#
/**
* @file
* Theme override for an 'input' #type form element.
*
* Available variables:
* - attributes: A list of HTML attributes for the input element.
* - children: Optional additional rendered elements.
*
* @see template_preprocess_input()
*/
#}
<button{{ attributes }}>attributes.value</button>{{ children }}