F
Filament11mo ago
Imam

Disable option Checkbox List more than 1 items

use Filament\Forms\Components\CheckboxList;

CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
->disableOptionWhen(fn (string $value): bool => $value === 'livewire')
use Filament\Forms\Components\CheckboxList;

CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
->disableOptionWhen(fn (string $value): bool => $value === 'livewire')
In the example above, we can disable the livewire options My question is, how to disable livewire and laravel in options?
Solution:
Solved! Just added with $set('technologies', ['special-option']); ```php ->disableOptionWhen(function (string $value, $state): bool { $tempData = $state ?? [];...
Jump to solution
4 Replies
Vp
Vp11mo ago
...'livewire' || $value === 'laravel'
Imam
ImamOP11mo ago
Thank you for your answer, this is my CheckboxList
CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
'special-option' => 'Special Option'
])
->live()
->disableOptionWhen(function (string $value, $state): bool {
$tempData = $state ?? [];
$founSpecialOption = in_array('special-option', $tempData);

if($founSpecialOption) {
return
$value === 'tailwind' || $value === 'alpine' || $value === 'laravel' || $value === 'livewire';
} else {
return false;
}
}),
CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
'special-option' => 'Special Option'
])
->live()
->disableOptionWhen(function (string $value, $state): bool {
$tempData = $state ?? [];
$founSpecialOption = in_array('special-option', $tempData);

if($founSpecialOption) {
return
$value === 'tailwind' || $value === 'alpine' || $value === 'laravel' || $value === 'livewire';
} else {
return false;
}
}),
The next condition is, I want that when special-option is selected, the other options will automatically be unchecked, because if we disable them when any option is already checked, it will result in the following situation:
Imam
ImamOP11mo ago
No description
Solution
Imam
Imam11mo ago
Solved! Just added with $set('technologies', ['special-option']);
->disableOptionWhen(function (string $value, $state): bool {
$tempData = $state ?? [];
$founSpecialOption = in_array('special-option', $tempData);

if($founSpecialOption) {
$set('technologies', ['special-option']);
return
$value === 'tailwind' || $value === 'alpine' || $value === 'laravel' || $value === 'livewire';
} else {
return false;
}
}),
->disableOptionWhen(function (string $value, $state): bool {
$tempData = $state ?? [];
$founSpecialOption = in_array('special-option', $tempData);

if($founSpecialOption) {
$set('technologies', ['special-option']);
return
$value === 'tailwind' || $value === 'alpine' || $value === 'laravel' || $value === 'livewire';
} else {
return false;
}
}),
Want results from more Discord servers?
Add your server