FilamentF
Filament2y 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')

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']);
->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;
    }
}),
Was this page helpful?