Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset filtered SELECT when filter SELECT selection changed #394

Open
printpagestopdf opened this issue Nov 4, 2024 · 3 comments
Open

Reset filtered SELECT when filter SELECT selection changed #394

printpagestopdf opened this issue Nov 4, 2024 · 3 comments
Assignees
Labels
Improvement Improvement to an existing feature
Milestone

Comments

@printpagestopdf
Copy link

printpagestopdf commented Nov 4, 2024

If filter and filter_by with two selects are used, the filtered select list stays on last selection if the filter select changes. I believe in most circumstances this is not the expected behaviour. It can lead to situations, where the filtered list has a value that is not allowed for the filter selection.

In my opinion the default behaviour should be, that the filtered list is reset always when the selection of the filter changes. If there is a need for the current behaviour, it could be enabled by an option?

In the moment I am using the following workaround:
public/vendor/bladewind/js/select.js:

callUserFunction = (item) => {
    /* Clear filtered list if available */
    if(this.toFilter)  eval('bw_' + this.toFilter).reset();
    ...........................................

clearFilter = (element, by = '') => {
    if (element) {
        const element_items = `.bw-select-${element}  .bw-select-items .bw-select-item`;

        /* remove all elements from filtered list if filterlist is empty */
        if(!dom_el(this.formInput).value) {
            dom_els(element_items).forEach((el) => {
                hide(el, true);
            });
            return;
        }
       ....................................

P.S.: For everybody who dislikes eval (from good reasons): in my real implementation I added a global Map for all selects (in select.blade.php) and use it without eval

BladewindVersion by composer.lock says: v2.6.4

@mkocansey
Copy link
Owner

Hello @printpagestopdf I believe the behaviour you seek is what currently is.
From the example here, https://bladewindui.com/component/select#another-select,

  • we have select 1 containing continents and select 2 containing countries
  • select 2 shows a couple of countries by default
  • if you select a continent from select 1, select 2 is filtered to show countries matching the continent selected in select 1
  • when you select another continent from select 1, the country list in select 2 is updated to show only countries matching the selected continent.
  • if you click on the reset icon in select 1, the countries in select 2 go back to the default (showing all countries).

Is this not what you described as the preferred behaviour of resetting the filter?

Also, please update to the latest version of the library. 2.6.4 is several versions behind.

@printpagestopdf
Copy link
Author

At first: excuse, my fault with the old Version, but I am working on an installation that somebody else made (and controls).

But for this case the behaviour of https://bladewindui.com/component/select#another-select, has still the same "problem". Lets make an example there:
if you select "Europe" in select 1 and select "Netherlands" in select 2.
Now change select 1 (select a different continent or clear it) => still Netherland is selected in select 2.
If you e.g. have this on an Form and send it now, you will have a forbidden combination of select 1 and select 2 value.

Perhaps there are use cases that want this behaviour, but it would be great, if there would be a mode that select 2 is always reset (selection and hidden input) when selection 1 changed.

Sorry for my bad english, hopefully the description is understandable.

Hello @printpagestopdf I believe the behaviour you seek is what currently is. From the example here, https://bladewindui.com/component/select#another-select,

* we have select 1 containing continents and select 2 containing countries

* select 2 shows a couple of countries by default

* if you select a continent from select 1, select 2 is filtered to show countries matching the continent selected in select 1

* when you select another continent from select 1, the country list in select 2 is updated to show only countries matching the selected continent.

* if you click on the reset icon in select 1, the countries in select 2 go back to the default (showing all countries).

Is this not what you described as the preferred behaviour of resetting the filter?

Also, please update to the latest version of the library. 2.6.4 is several versions behind.

At first: excuse, my fault with the old Version, but I am working on an installation that somebody else made (and controls).

But for this case the behaviour of https://bladewindui.com/component/select#another-select, has still the same "problem". Lets make an example there:
if you select "Europe" in select 1 and select "Netherlands" in select 2.
Now change select 1 (select a different continent or clear it) => still Netherland is selected in select 2.
If you e.g. have this on an Form and send it now, you will have a forbidden combination of select 1 and select 2 value.

Perhaps there are use cases that want this behaviour, but it would be great, if there would be a mode that select 2 is always reset (selection and hidden input) when selection 1 changed.

Sorry for my bad english, hopefully the description is understandable.

@mkocansey
Copy link
Owner

Oh. I understand you perfectly now. You have a valid point. I'll add an attribute that allows you to clear the child if the parent value changes.

@mkocansey mkocansey self-assigned this Nov 11, 2024
@mkocansey mkocansey added bug Something isn't working Improvement Improvement to an existing feature and removed bug Something isn't working labels Nov 11, 2024
@mkocansey mkocansey moved this to Ready in BladewindUI Nov 11, 2024
@mkocansey mkocansey added this to the v2.8.0 milestone Nov 11, 2024
@mkocansey mkocansey moved this from Ready to In progress in BladewindUI Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Improvement to an existing feature
Projects
Status: In progress
Development

No branches or pull requests

2 participants