Skip to content

Instantly share code, notes, and snippets.

@keepanitreel
Created December 29, 2023 01:27
Show Gist options
  • Save keepanitreel/f8518a00a15af0d843120f26dec34427 to your computer and use it in GitHub Desktop.
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
/**
* 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