Not able to select newly created options using CreateOptionsForm until refresh

Hey y'all, I've created some monstrosity. I'm sure there's a better way of doing this, and if you can help point me in the right direction I'd really appreciate it. I added CreateOptionsForms to each of the select fields, and they work, but the issue is that after creation, while I can see the option in the dropdown, if I try to actually select it it will pretend to let me for half a second, but then reset the select field to "Select an option". It's not actually selectable until I refresh the page. A second issue is, after creating the option, i'd like that new option to be automatically selected by the field. I've tried to accomplish this with the Product select but the approach I've taken just isn't doing anything. I'm imagining this is related to the first issue, the option not actually being selectable.
Solution:
I think you are supposed to return the id of the newly created model (as opposed to the model instance). Something like: ```php return \App\Models\Tos::create([ 'product_id' => $productId,...
Jump to solution
2 Replies
Solution
dissto
dissto2mo ago
I think you are supposed to return the id of the newly created model (as opposed to the model instance). Something like:
return \App\Models\Tos::create([
'product_id' => $productId,
'title' => $data['title'],
'company_id' => $companyId,
])->getKey(); // or ->id
return \App\Models\Tos::create([
'product_id' => $productId,
'title' => $data['title'],
'company_id' => $companyId,
])->getKey(); // or ->id
🤔
Vexmachina
Vexmachina2mo ago
That worked, thank you!