Created
December 29, 2023 01:27
-
-
Save keepanitreel/f8518a00a15af0d843120f26dec34427 to your computer and use it in GitHub Desktop.
FilamentPHP Select Input Actions for removing all / adding all in a Multiple Select input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Credit Sandro Gehri | |
* https://twitter.com/gehrisandro | |
*/ | |
use Filament\Forms\Components\Select; | |
use Filament\Forms\Components\Actions\Action; | |
Select::make('foo') | |
->options(['read','write','execute']) | |
->multiple() | |
->live() | |
->hintActions([ | |
Action::make('remove_all') | |
->visible(fn(Select $component)=>c$component->getState() !== []) | |
->action(fn(Select $component)=> $component->state([])), | |
Action::make('select_all') | |
->visible(fn(Select $component)=> component->getState() !== []) | |
->action(fn(Select $component)=> $component->state(array_keys($component->getOptions()))) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment