Default value and reactive fields
Hi there!
Guys, what's the problem with the default value of the second select 'method'?
I know that if the string
if (!$action) return [];
is erased, everything works.
So the problem is in the empty array that we return when action is not selected. But even after selecting the 'action' is performed, the default value for 'method' is not stated, it is still null and we see a placeholder here. Action is reactive. What I'm doing wrong? Thanks!
Forms\Components\Select::make('action')
->options(function (Closure $get) {
return Event::getAvailableActionsForSelect($get('trigger_type'));
})
->reactive(),
Forms\Components\Card::make()
->schema(function (Closure $get) {
$action = $get('action');
if (!$action) return [];
return [
Forms\Components\Select::make('method')
->options([
'get' => 'GET',
'POST' => 'POST',
'PUT' => 'PUT',
'PATCH' => 'PATCH',
'DELETE' => 'DELETE',
])
->default('get')
]
})
4 Replies
default values are only filled when the form is first loaded
you need to use afterStateUpdated() on the first field to $set() the value of the second field appropriately
Thanks a lot, Dan! That works for me! It might doesn't look perfect for fields that are in different classes, but I caught the idea! π
make sure that the state of other fields is in the correct format
Yes, thanks. I'll try different things like that. I have some similar tasks.