F
Filament7mo 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
KodaOP7mo 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
LeandroFerreira7mo ago
did you make it live()?
Koda
KodaOP7mo 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
LeandroFerreira7mo 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
KodaOP7mo ago
Thank you. This work. Have you also a solution to uncheck the value for a better user experience?
toeknee
toeknee7mo ago
I would get the current values, and then remove the ones you are disabiling and set it
Koda
KodaOP7mo ago
@toeknee Thank you. have you an example?
toeknee
toeknee7mo 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