F
Filament6mo ago
Koda

Disable/Hide Checkbox item in CheckboxList

I use CheckboxList / RadioDeck. Let's say I have 5 Values A, B, C, D and E. Gives a solution to uncheck,disable(or hide) C and D if I check A, and reverse if I uncehck A?
9 Replies
Koda
KodaOP6mo ago
@Leandro Ferreira Thank you. Is disableOptionWhen not only to disable an option on page load? I need multiple Rule To disable D if I check A, Disable D and E if I check B,...
LeandroFerreira
LeandroFerreira6mo ago
did you make it live()?
Koda
KodaOP6mo ago
Thank you. I forgot live(). But what is the solution to uncheck and disable or hide? I thought I found a solution with false but this is wrong
CheckboxList::make('options')
->options([
'a' => 'A',
'b' => 'B',
'c' => 'C',
'd' => 'D',
])
->live()
->disableOptionWhen(function($value, Set $set, $state) {
if(in_array('a', $state)) {
//if($value === 'a') { # value is allways a...?
$set('options.b', false);
}
}),
CheckboxList::make('options')
->options([
'a' => 'A',
'b' => 'B',
'c' => 'C',
'd' => 'D',
])
->live()
->disableOptionWhen(function($value, Set $set, $state) {
if(in_array('a', $state)) {
//if($value === 'a') { # value is allways a...?
$set('options.b', false);
}
}),
LeandroFerreira
LeandroFerreira6mo ago
->disableOptionWhen(fn (string $value, ?array $state): bool => in_array('a', $state) && $value === 'b')
->disableOptionWhen(fn (string $value, ?array $state): bool => in_array('a', $state) && $value === 'b')
Koda
KodaOP6mo ago
Thank you. This work. Have you also a solution to uncheck the value for a better user experience?
toeknee
toeknee6mo ago
I would get the current values, and then remove the ones you are disabiling and set it
Koda
KodaOP6mo ago
@toeknee Thank you. have you an example?
toeknee
toeknee6mo ago
DisableOpenWhen should actually do that. But if it's not just do:
CheckboxList::make('options')
->options([
'a' => 'A',
'b' => 'B',
'c' => 'C',
'd' => 'D',
])
->live()
->disableOptionWhen(function($value, Set $set, $state) {
if(in_array('a', $state) && $state['a']) {
$set('options.b', false);
}
}),
CheckboxList::make('options')
->options([
'a' => 'A',
'b' => 'B',
'c' => 'C',
'd' => 'D',
])
->live()
->disableOptionWhen(function($value, Set $set, $state) {
if(in_array('a', $state) && $state['a']) {
$set('options.b', false);
}
}),
Want results from more Discord servers?
Add your server