F
Filamentβ€’2y ago
Rus

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
Dan Harrin
Dan Harrinβ€’2y ago
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
Rus
RusOPβ€’2y ago
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! πŸ‘
Dan Harrin
Dan Harrinβ€’2y ago
make sure that the state of other fields is in the correct format
Rus
RusOPβ€’2y ago
Yes, thanks. I'll try different things like that. I have some similar tasks.
Want results from more Discord servers?
Add your server