Deactivate filters when one filter activates
Hey - following scenario:
Given I got Filter A, B and C. C is a toggle-filter and I want Filter A+B deactivated as soon as C is activated. How do I achieve this? Thanks. 🙂
10 Replies
@husky110 Can you share the code of your filters?
yes - but gotta hide some of it.
For context -> we're in a resource. I want hat filter "fast_open" deactivated any other filters when it's activated.
Do not get confused by the m__ - I'm using my own translation-plugin (which I might release as a package later).
I think you'll need to extend the
Filter
class and override the getFormField()
method.
Maybe something like this:
You should be able to hide them with the hidden() or visible() method just like you would any other form component. Is that not working? You can just check against the tableFilter array
hidden(fn ($livewire) => $livewire->tableFilters…
.
dd($livewire->tableFilters) to see the filter array when you have a filter turned on
Filters are reactive by default so you don’t need to add reactive().Huh... So basically we have two possible ways here... I think I will go with @pboivin's solution here, cause I think I will have to use it multiple times and just making a "KillerFilter" or sth. along those lines is better in readability and useability than having to rewrite the function multiple times. If it were only one, @kennethsese's solution would make sense tho.
Thank you guys. 🙂
Yeah, I think re-setting vs. hiding filters are two valid use-cases, you have a few options there 👌
filterKiller() is a great method name!!! 😂
it's class KillerFilter tho... 😄
Yep - which is why I try to state it as clearly as possible, so if someone finds this thread via searching, they get the full picture and hopefully a good solution to their problem. 🙂
If anyone needs it - here's the template:
Thanks @pboivin and @kennethsese
Had to update my template:
The previous template produced failures when there is more than one KillerFilter present.