making one filter disappear when another is active #1264
-
I have two filters in my CRUD:
Here are the relevant methods in the model that correspond to the addClause calls:
The thing is... it doesn't make sense to even show a filter for "paid online" when the "unpaid" filter is active. Like if you've paid online you've implicitly paid. By that same logic it also doesn't make sense to show the "paid online" filter when the "unpaid" filter is active. Any ideas as to how I can make one filter disappear when another is active? I tried adding |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
To make one filter disappear when another is active, you can use the CRUD::filter('unpaid')
->type('simple')
->whenActive(function() {
CRUD::addClause('unpaid');
CRUD::filter('paid_online')->remove();
})->else(function() {
CRUD::addClause('paid');
});
CRUD::filter('paid_online')
->type('simple')
->whenActive(function() {
CRUD::addClause('paidOnline');
CRUD::filter('unpaid')->remove();
}); In this solution, we're using the Here's what's happening:
This approach should make one filter disappear when the other is active, as you requested. The reason your original attempt didn't work is that the For more information on filter methods and how to manipulate them, you can refer to the Backpack CRUD API Cheat Sheet and the Backpack Fluent Syntax documentation. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: CRUD Fluent API|Other Chained Methods |
Beta Was this translation helpful? Give feedback.
-
The filters works on ajax and they can't be removed without page reload. For now, you can use dropdown or select2 filter in your use case, so one status is selected at a time. CRUD::filter('status')
->type('dropdown')
->values([
'unpaid' => 'unpaid',
'paidOnline' => 'paidOnline',
])
->whenActive(function ($value) {
CRUD::addClause('where', 'status', $value);
}); |
Beta Was this translation helpful? Give feedback.
Hey @prescriptionlifeline
The filters works on ajax and they can't be removed without page reload.
For now, you can use dropdown or select2 filter in your use case, so one status is selected at a time.
For example: