Filament Select All Action

Filament Select All Action

Nov 19, 2024 4:00 PM (11 days ago)

Demo

// in register method - AppServiceProvider.php
 \Filament\Forms\Components\Select::macro('selectAllHintActions', function () {
            /** @var Filament\Forms\Components\Select $this */
            return $this->hintActions([
                \Filament\Forms\Components\Actions\Action::make('select_all')
                    ->label(__('Select All'))
                    ->action(fn (Select $component) => $component->state(
                        array_keys($component->getOptions())
                    )),
                \Filament\Forms\Components\Actions\Action::make('deselect_all')
                    ->label(__('Deselect All'))
                    ->action(
                        fn (\Filament\Forms\Set $set, Select $component) => $set($component->getName(), []),
                    ),
            ]);
        });

// in your resource/form/page...

return [
    Select::make('supplier_type_ids')
                ->label(__('Suppler Type'))
                ->searchable()
                ->preload()
                ->multiple()
                ->live()
                ->options(function () {
                    return SupplierType::query()->pluck('name', 'id');
                })
                ->selectAllHintActions() 🌟🌟🌟🌟🌟🌟🌟🌟
                ->required(),
];
My Newsletter

I send out an email every so often about cool stuff I'm working on or launching. If you dig, go ahead and sign up!

No spam, only goldden nuggets 💎

Comments

Ahmed Nagi - Powerd By Vuepress . Hosted with GitHub and Netlify .