Problem/Motivation
When using a range select filter and you try to remove it it does not remove the selection.
The select is using the value to clear it, but the value when using a multiple values are for example min|max. And not the actual value of the selected input for example 2000-5000. So when trying to clear the value the selector is empty.
In the onRemoveClick function:
input.querySelectorAll(`[value="${value}"]`).forEach((element) => {
element.selected = false;
});
Steps to reproduce
Add a between filter to a view with a min and max field and expose it.
To make it a select use a form_alter hook and change the fields accordingly.
Add a summary field with remove links.
Use the filter to show the summary.
Click on the remove link (icon).
The filter is not cleared.
Proposed resolution
In the onRemoveClick function different inputs are already handled. We can also add select to it and just clear everything that is selected. The value is probably used to handle multiple selects, which you will "never" use for a range select. So also only do it for single selects and let the multiple select fallback on the existing else.
Something like this:
if (input.tagName === 'INPUT') {
.......existing code
}
else if (input.tagName === 'SELECT' && !input.hasAttribute('multiple')) {
input.querySelectorAll(`[selected="selected"]`).forEach((element) => {
element.selected = false;
});
}
else {
input.querySelectorAll(`[value="${value}"]`).forEach((element) => {
element.selected = false;
});
}
Issue fork views_filters_summary-3533325
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
mably commented@michael.acampora how do you get a select in your range filter ? I only get simple min/max input fields. I would like to be able to reproduce it locally before merging.
BTW ChatGPT gives the following warning:
But Claude says the opposite 😉 So it looks like we can keep it.
Comment #5
michael.acampora commented@mably I forgot to add a step for reproduce my bad: For my use case the input fields are converted to select fields in a #[Hook('form_views_exposed_form_alter')].
I checked caniuse for the selectedIndex:
https://caniuse.com/mdn-api_htmlselectelement_selectedindex
Support seems good, I did not check the a11y angle though.
Comment #6
mably commentedOk, I get it, let's merge it as is then.
Comment #8
mably commentedComment #9
mably commentedIncluded in 3.2.0-rc1 release.