Laravel filament dynamic select field

151 Views Asked by At

i have one question. how do i disable a select column if another prior select or toggle in the same form has been selected as false. To give some context i have an address form and i want to disable the days field on the form when the Status column in the same form has been selected as closed. I've tried many different combinations to make this work but i can't seem to find a solution This is my form

 public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('user_id')
                    ->default(auth()->user()->id)  // set default value to authenticated user ID  // hide if $userId is not null
                    ->relationship('user', 'id')
                    ->visible(false)  // hide in create view
                    ->required(),
                Toggle::make('status')
                    ->default(true)
                    ->live()
                    ->required(),
                Select::make('day')
                    ->enum(Days::class)
                    ->options(Days::class),
                Forms\Components\DatePicker::make('open')
                    ->default(null),
                Forms\Components\DatePicker::make('close')
                    ->default(null),
                Forms\Components\TextInput::make('phone')
                    ->tel()
                    ->maxLength(255),
            ]);
    }
1

There are 1 best solutions below

0
MDSolanki On BEST ANSWER

just add below code to your day select input

use Filament\Forms\Get;

Select::make('day')
    ->enum(Days::class)
    ->options(Days::class)
    ->disabled(fn (Get $get) => !$get('status')),

here link to filament documentation for Disabling a field