Toggle Filter only used when On?
I have a table filter like so . i only want it applied when its toggled on and it do nothing when its off. How can i do that?
19 Replies
On what version are you? I have a simular toggle and it work fine
My guess is your relationship with criteria may not be defined?
maybe use tenary filter ?
it has true and false and blank state
in your closure,
something like this? might need to adjust the $state param
that does partly work, but query string still has
?tableFilters[criteria_id][isActive]=0
when its off->when($state !== 0, fn….)
Wrap your where inside a when.
Also keep in mind that the toggle doesn’t have a null. It’s always true or false when it’s interacted with.
Right, thats the problem. I think for most people, thats not how they want a toggle filter to work. Could easily be a wrong assumption
well, it's a binary input. on / off, true / false,
makes sense to me
it's not about the filter is about the input your using for the filter.
yes, on/off. I either want hte filter on or i want it off.
if you need null / true / false, then you'll need a select since it provides for more than 2 options
Think about it this way, say you have a toggle filter for published / draft, the on / off mentality there would break since it wouldn't run the filter for items set to draft.
you're not turning the filter on or off, you're toggle the state of the records to be filtered
no i get that, im just not looking for two states. I either want to filter by drafts only or i dont want to filter at all
I understand that. Thats just not my desired result
then wrap it in a when to check the state of the toggle.
it's operating exactly like it should, you're just trying to use it in a different way, so you'll have to make checks against it's state to modify the outcome
i dont think that when() will affect the querystring when its off, which is my desired outcome as mentioned 15 minutes ago 😛
you're right it won't affect the query string.
but changing the query string isn't what you need.
im already getting the proper results
then why are we discussing this. LOL
i have no idea as i already confirmed that 15 minutes ago that the filtering is working properly, it just doesnt have the querystring state that i would prefer. NOw when ever the table is loaded, the querystring always has a default state of
?tableFilters[criteria_id][isActive]=0
. Its not a huge deal, but i would prefer not ot have it if a filter really isnt applied, which it isnt10-4
guess i missed the comment where you said it was giving you the correct results. sorry.