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:Jump to 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,...
8 Replies
Solution
I think you are supposed to return the id of the newly created model (as opposed to the model instance). Something like:
🤔
That worked, thank you!
Selecting the newly created model doesn't work when we use a model as a relationship instead of an array of options. Example
CreateOptionUsing() is how to save the model. So you’re not actually saving the model. Based on what you showed. CreateOptionForm() will handle the saving automatically.
Just depends on what you need.
If I am creating the model with $country = Country::query()->create($data)
The problem is that it is not selected, although I have seen that after creating another field in the same way, the previous one gets populated.
The form code is this:
The Region model has these relationships:
@xechino did you manage to resolve this? I'm having the same issue and thinking of raising a bug as I don't believe this is the intended behaviour
@NickBell, unfortunately, I haven't been able to resolve the issue yet. I've put it aside to revisit in the future, as I haven't had the time to create a new post or investigate further. If you do raise a bug report, please let me know how it goes!
up people found a way to refresh the options in the select ?
the only way I found to update the values is to have live() and preload() together.