F
Filament15mo ago
nwalty

Dynamic Fields Based on Select Option Issue

I am encountering a issue with dynamic form fields. When attempting to use any form layout components within the match function the dynamic select jumps to null and nothing else happens (continues to display the default form fields). I haven't received any errors on console for this issue. When not including any layout components the form fields load as expected.
Forms\Components\Select::make('type')
->label('Contest Type')
->options([
'Contest' => 'Contest (single game)',
'Tournament' => 'Tournament',
])
->default('Contest')
->live()
->afterStateUpdated(fn (Forms\Components\Select $component) =>
$component->getContainer()
->getComponent('dynamicTypeFields')
->getChildComponentContainer()
->fill()
)
->visibleOn('create'),
Forms\Components\Grid::make(2)
->schema(fn (Get $get): array =>
match ($get('type')) {
'Tournament' => [
Forms\Components\Fieldset::make() //Remove this and it works
->schema([
Forms\Components\TextInput::make('name')
->required(),
])
],
default => [
Forms\Components\DateTimePicker::make('start_at')
->label('Date'),
],
}
)
->key('dynamicTypeFields'),
Forms\Components\Select::make('type')
->label('Contest Type')
->options([
'Contest' => 'Contest (single game)',
'Tournament' => 'Tournament',
])
->default('Contest')
->live()
->afterStateUpdated(fn (Forms\Components\Select $component) =>
$component->getContainer()
->getComponent('dynamicTypeFields')
->getChildComponentContainer()
->fill()
)
->visibleOn('create'),
Forms\Components\Grid::make(2)
->schema(fn (Get $get): array =>
match ($get('type')) {
'Tournament' => [
Forms\Components\Fieldset::make() //Remove this and it works
->schema([
Forms\Components\TextInput::make('name')
->required(),
])
],
default => [
Forms\Components\DateTimePicker::make('start_at')
->label('Date'),
],
}
)
->key('dynamicTypeFields'),
2 Replies
Lara Zeus
Lara Zeus15mo ago
I think you cant use Fieldset or any layout component its only fills the getChildComponentContainer not ChildChildComponent i guess 🙂
nwalty
nwaltyOP15mo ago
Ok that was what I was kinda thinking. Thanks!

Did you find this page helpful?