Default Select
When I use a toggle to hide a select the default only works when creating a record. When editing the default is always the first option
2 Replies
Default only works on create, by the time it’s in edit mode it’s assumed that it has a value.
You would have to $set it on the edit page if it doesn’t have a value on the record.
Hello! i need to continue this post because, i have the same problem but maybe i don't understand how to use $set.
This is my select:
Select::make('category')->label('Category ad')
->options(function(Ad $record):array {
return array_keys($record->city->categories);
})
->default(fn (Set $set, Ad $record) => $set('category', array_search($record->category['name'], array_keys($record->city->categories))))
array_keys($record->city->categories) = ['Mobile', 'Phone', etc]
"category" is a real table column, but inside it i have a array like that ["name" => "Mobile", "point" => '1'], i try to use $set with array_search for having index of categories using "name" key, but nothing happens.
My form is loaded with EditAction.
Thanks you
i resolve with formatStateUsing