F
Filament16mo ago
Antoine

createOptionUsing() doesn't select new value

Hello everyone, I'm pretty confused because I don't understand where is my error. I have this Select in a Form :
Select::make('filter')
->options(Filter::where('user_id', auth()->user()->id)
->pluck('name', 'id'))
->createOptionForm([
TextInput::make('name')
->required(),
])
->createOptionUsing(function($data) {
$name = $data['name'];
$filter = Filter::create([
'user_id' => auth()->user()->id,
'name' => $name,
]);
return $filter->id;
})
->afterStateUpdated(...)
->live()
Select::make('filter')
->options(Filter::where('user_id', auth()->user()->id)
->pluck('name', 'id'))
->createOptionForm([
TextInput::make('name')
->required(),
])
->createOptionUsing(function($data) {
$name = $data['name'];
$filter = Filter::create([
'user_id' => auth()->user()->id,
'name' => $name,
]);
return $filter->id;
})
->afterStateUpdated(...)
->live()
When I submit my modal, I return the id of my model that I have just created. I debugged $filter->id with dd() before returning it and it exists as well as my row in the database. But it returns null in my component after submit. However, if I return a value manually from an already existing line like: return 1; It selects it well. I tried on another form and I still have the same problem when I create a model row. Did I do something wrong? Or is it another problem? I think I am returning the model before it is created in the Select options, is there a method for resolve this?
2 Replies
Antoine
AntoineOP16mo ago
It seems a bug... Same problem https://discord.com/channels/883083792112300104/1148925136553123850/1148925136553123850 and I resolve it with :
->searchable()
->preload()
->searchable()
->preload()
Malcolm Turntbull
I ran into this exact same problem, and the exact same solution worked for me. No idea why!

Did you find this page helpful?