Mar 2, 2024
0
Level 1
Dynamic link with Select input not working on Edit page
Hello,
I have a Select input on my form, which can dynamically change other inputs based on the item selected. The schema looks like this:
->schema([
Select::make('attribute_option_id')
->relationship(name: 'attribute_option', titleAttribute: 'name')
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('valueFields')
->getChildComponentContainer()
->fill()),
Group::make()
->schema(fn (Get $get): array => match ($get('attribute_option_id')) {
'1' => [
ColorPicker::make('value')
->required(),
],
default => [
TextInput::make('value')
->required(),
],
})
->key('valueFields')
->columnSpan(1),
])
My issue is that this works fine when I first use it when creating an item, but once it is created the correct value appears in the Select but the Group schema doesn't change accordingly (so where I would expect a ColorPicker there is a TextInput instead). Any idea why?
Please or to participate in this conversation.