F
Filamentβ€’10mo ago
Adapt.Patrick

Newly created option isn't selected when returning from createOptionForm()

As per the attached screen recording gif, the selected item in the menu doesn't reflect the newly created record when creating a new entry via the createOptionForm() method (as below).
Select::make('project_type_id')
->columnSpan(6)
->hidden(!$userIsAdmin)
->options(ProjectType::all()->pluck('type', 'id')->toArray())
->relationship('projectType', 'type')
->createOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->editOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->manageOptionActions(function ($action) {
$action
->modalWidth('lg')
->modalFooterActionsAlignment('end');
})
->preload()
->required()
Select::make('project_type_id')
->columnSpan(6)
->hidden(!$userIsAdmin)
->options(ProjectType::all()->pluck('type', 'id')->toArray())
->relationship('projectType', 'type')
->createOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->editOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->manageOptionActions(function ($action) {
$action
->modalWidth('lg')
->modalFooterActionsAlignment('end');
})
->preload()
->required()
Expected behaviour When returning from creating a new entry using the createOptionForm() method, I expect that item to be auto-selected in the corresponding Select menu.
No description
Solution:
Try to use ->native(false) on the select πŸ€” Is there a reason why you use both options and relationship?...
Jump to solution
4 Replies
Adapt.Patrick
Adapt.PatrickOPβ€’10mo ago
It's worth mentioning it seems others may be experiencing something similar (e.g https://discord.com/channels/883083792112300104/1198986989597368400).
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Vp
Vpβ€’10mo ago
I think this is a bug, try it out now and same thing happen to me as well, suggesting you to submit an issue in github if possible
Solution
dissto
disstoβ€’10mo ago
Try to use ->native(false) on the select πŸ€” Is there a reason why you use both options and relationship?
Adapt.Patrick
Adapt.PatrickOPβ€’10mo ago
Thanks @dissto! That seems to have fixed the issue! πŸ™Œ As it happens I noticed the duplication of ->options() and ->relationship() before your message and had already removed one of these. πŸ‘Œ For anybody else experiencing something similar, ->native(false) appears to have solved the problem for me. πŸ₯³

Did you find this page helpful?