Conditional Rendering in filament forms
I have a form and I want when a use selects sponsorChild I show the children dropdown , when i select Rescue Baby I show the baby dropdown
->schema([
Forms\Components\Select::make('sponsor.sponor_id')
->relationship('sponsor', 'first_name')
->native(false)
->label("Sponsor Name")
->searchable()
->preload(),
Forms\Components\Select::make('type')
->live()
->options([
'RescueBaby' => 'Rescue Baby',
'SponsorChild' => 'Sponsor Child',
])
->searchable()
->preload()
->label("Type")
->required(),
Forms\Components\Select::make('child_id')
->label('Children Name')
->options(Children::all()->pluck('first_name', 'id'))
->searchable()
->visible(fn (Form $component) => $component->getState() === 'SponsorChild')
->preload(),
Forms\Components\Select::make('baby_id')
->label('Babies Homes')
->options(Children::all()->pluck('first_name', 'id'))
->searchable()
->visible(fn (Form $component) => $component->getState() === 'RescueBaby')
->preload(),
]);
->schema([
Forms\Components\Select::make('sponsor.sponor_id')
->relationship('sponsor', 'first_name')
->native(false)
->label("Sponsor Name")
->searchable()
->preload(),
Forms\Components\Select::make('type')
->live()
->options([
'RescueBaby' => 'Rescue Baby',
'SponsorChild' => 'Sponsor Child',
])
->searchable()
->preload()
->label("Type")
->required(),
Forms\Components\Select::make('child_id')
->label('Children Name')
->options(Children::all()->pluck('first_name', 'id'))
->searchable()
->visible(fn (Form $component) => $component->getState() === 'SponsorChild')
->preload(),
Forms\Components\Select::make('baby_id')
->label('Babies Homes')
->options(Children::all()->pluck('first_name', 'id'))
->searchable()
->visible(fn (Form $component) => $component->getState() === 'RescueBaby')
->preload(),
]);
0 Replies