Array of `Select` doesn't fill from state

I'm making a system that maps CSV columns to an existing table. For this i have a TableMapping model and resource with a single json field (key-value pairs). I have casted this field to object in the model, my resource looks like this:
public static function form(Form $form): Form
{
$schema = [];
$dbTypes = DB::select('SELECT * FROM pragma_table_info(\'sor_organisations\')');
$dbToOptions = array_combine(array_map(fn($type) => $type->name, $dbTypes), array_map(fn($type) => $type->name, $dbTypes));
foreach ($form->getRecord()->mapping as $key => $value) {
$schema[] = Forms\Components\Select::make('mapping.' . $key)
->label($key)
->options($dbToOptions)
->statePath('mapping.' . $key)
->default($value);
}
return $form
->schema($schema)->columns(1);
}
public static function form(Form $form): Form
{
$schema = [];
$dbTypes = DB::select('SELECT * FROM pragma_table_info(\'sor_organisations\')');
$dbToOptions = array_combine(array_map(fn($type) => $type->name, $dbTypes), array_map(fn($type) => $type->name, $dbTypes));
foreach ($form->getRecord()->mapping as $key => $value) {
$schema[] = Forms\Components\Select::make('mapping.' . $key)
->label($key)
->options($dbToOptions)
->statePath('mapping.' . $key)
->default($value);
}
return $form
->schema($schema)->columns(1);
}
This all works fine, i get all the dropdowns, along with their options based on table column names. But when i select a value, and save the mapping, and then refresh the browser page, all dropdowns goes back to the default state of "Select an option". I have checked the DB, the values are saved correctly. If i dd($schema) i can see the values are correctly hydrated into their appropriate dropdowns, it's just not filled in the view. Anyone got any ideas?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server