From d72979b82f7eabb41b87fb1e3acee6de3d33a62d Mon Sep 17 00:00:00 2001 From: Sean Blommaert <info@seanblommaert.nl> Date: Mon, 11 Apr 2022 12:41:59 +0200 Subject: [PATCH] Added once() to make sure AJAX behavior is only attached once to each button. --- core/modules/views/js/ajax_view.es6.js | 23 ++++++++++++----------- core/modules/views/js/ajax_view.js | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/modules/views/js/ajax_view.es6.js b/core/modules/views/js/ajax_view.es6.js index e85ef75fc6f0..317f6d5d0273 100644 --- a/core/modules/views/js/ajax_view.es6.js +++ b/core/modules/views/js/ajax_view.es6.js @@ -137,18 +137,19 @@ 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], button[type=submit], input[type=image]', - this.$exposed_form, - ) - .not('[data-drupal-selector=edit-reset]') - .each(function (index) { - const selfSettings = $.extend({}, that.element_settings, { - base: $(this).attr('id'), - element: this, - }); - that.exposedFormAjax[index] = Drupal.ajax(selfSettings); + once( + 'attach-ajax', + $( + 'input[type=submit], button[type=submit], input[type=image]', + this.$exposed_form, + ).not('[data-drupal-selector=edit-reset]') + ).forEach(function (button, index) { + const selfSettings = $.extend({}, that.element_settings, { + base: $(this).attr('id'), + element: button, }); + that.exposedFormAjax[index] = Drupal.ajax(selfSettings); + }); }; /** diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js index f76ddd72ae43..2eaacc494c40 100644 --- a/core/modules/views/js/ajax_view.js +++ b/core/modules/views/js/ajax_view.js @@ -80,10 +80,10 @@ Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () { var that = this; this.exposedFormAjax = []; - $('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) { + once('attach-ajax', $('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]')).forEach(function (button, index) { var selfSettings = $.extend({}, that.element_settings, { base: $(this).attr('id'), - element: this + element: button }); that.exposedFormAjax[index] = Drupal.ajax(selfSettings); }); -- GitLab