Select option is "0" after creating an entry through Select::make(...)->createOptionForm(...)
What I'm trying to do :
Allow users to add an option in a relationship select using the createOptionForm mechanism.
What I did :
I've added two configuration methods to my Select component :
My issue is :
When the create option modal is closed after the data has been input, the selected item in the Select just shows "0" instead of the expected titleAttribute (handle_and_name) for the data inserted. The data is inserted without issue in the database, and the code in the createOptionAction is working as expected (this code is actually responsible for setting the primary key value).
I'm however using two specialties in my code :
1) The titleAttribute (handle_and_name) for the select is a virtual mysql column (generated)
2) The primary key for the Model created in the CreateOption form is a string, and not an integer.
As I've used the "Create Option" functionality in other parts of my code, I believe that the issue might be related to one or both of theses specialties being present.
What I want to do
One thing that I want to try is to refresh the model after it's been created to make sure that the virtual column value is present in the PHP object. For this, I tried to add a callback using the "after" method on the CreateAction, but I'm not getting anything injected in the $record variable, so I'm probably using the wrong hook.
Has anyone seen a similar problem and might have a hint on what to try next?
4 Replies
This is probably, not relevant, but the Select component is located inside a Wizard.
Hey @fblaser did you manage to fix this?
I think I'm experiencing something similar - as you'll see in the attached gif. When returning from the
createOptionForm
method, the corresponding Select
element defaults to no selection. π€Hi @Adapt.Patrick, looks a bit similar indeed.
Looking at the code, it looks like the working solution I found was to set the value of the select manually using the afterStateUpdated callback.
Nice one, thanks for that. I'll take a look at a similar approach if I don't get any feedback to my own post I recently created (https://discord.com/channels/883083792112300104/1240059016152088586) π