F
Filamentβ€’11mo ago
fblaser

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 :
Select::make('owner_handle')
->label('Owner')
->relationship(
name: 'owner',
titleAttribute: 'handle_and_name',
modifyQueryUsing: /* code not related to the issue */
->noSearchResultsMessage('No owner found.')
->forceSearchCaseInsensitive()
->createOptionForm([ /*standard components for the form*/ ])
->createOptionAction(/* code to retrieve one of the fields from an external source */)
->searchable(),
Select::make('owner_handle')
->label('Owner')
->relationship(
name: 'owner',
titleAttribute: 'handle_and_name',
modifyQueryUsing: /* code not related to the issue */
->noSearchResultsMessage('No owner found.')
->forceSearchCaseInsensitive()
->createOptionForm([ /*standard components for the form*/ ])
->createOptionAction(/* code to retrieve one of the fields from an external source */)
->searchable(),
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?
No description
4 Replies
fblaser
fblaserOPβ€’11mo ago
This is probably, not relevant, but the Select component is located inside a Wizard.
Adapt.Patrick
Adapt.Patrickβ€’7mo ago
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. πŸ€”
No description
fblaser
fblaserOPβ€’7mo ago
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.
Adapt.Patrick
Adapt.Patrickβ€’7mo ago
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) πŸ‘
Want results from more Discord servers?
Add your server