Problem/Motivation
------------------
In core/modules/views/js/ajax_view.js, when building the next AJAX request
for a view's pager/exposed-form submit, the code checks whether a URL
parameter is "already part of the exposed form" like this:
this.$exposed_form.find(`input[name="${name}"]`).length === 0
This has two problems:
1. The selector only matches `input` elements, never `select`. Any
select-based exposed filter (e.g. a multi-value select2 widget) is never
recognized as "already in the form".
2. A multi-value field's actual form control is named e.g. "intake[]",
while a previously-pushed URL (built server-side, typically via PHP's
http_build_query(), which defaults to indexed bracket notation) contains
keys like "intake[0]", "intake[1]" - different strings from "intake[]",
so even an exact-name match against `select` would still fail.
As a result, once a select-based multi-value exposed filter is used, stale
or removed values keep reappearing/accumulating in the URL on every
subsequent AJAX submission of that view (intake[0]=..., intake[1]=...,
intake[2]=... piling up), because the exposed form's own current value is
concatenated onto the never-cleaned-up stale one instead of replacing it.
Steps to reproduce
-------------------
1. Create a view with an AJAX-enabled exposed filter on a multi-value field
using a select-based widget (e.g. Better Exposed Filters' select2, or any
multi-value entity reference/taxonomy exposed filter rendered as
2. Submit the exposed form with one value selected.
3. Submit again with a different value selected (or with the previous value
removed).
4. Observe that the resulting URL/request still contains the old value(s)
in addition to the new one, accumulating further with each submission.
Proposed resolution
--------------------
Change the check to also match `select`/`textarea` elements (`:input`
instead of `input`), and strip any bracket suffix from the URL parameter
name before comparing, so indexed URL parameters (name[0], name[1], ...)
are correctly recognized as belonging to the same field as its actual
(unindexed, `name[]`) form control.
| Comment | File | Size | Author |
|---|---|---|---|
| views_ajax_select_exposed_filter_cleanup.patch | 2.07 KB | hulyakucuk |
Comments
Comment #2
hulyakucuk commented