F
Filamentβ€’13mo ago
LiruLiruLiru

Issue with Form property not showing when using ->multiple() in Select field

Hey everyone! πŸ‘‹ I'm currently facing an issue with my Filament form, and I could use some help. Problem: I have a form with a Select field using ->multiple() in the ->action() custom action. I'm not able to see my $data["fields"] even though it's defined in my form. Strangely, if I remove ->multiple() from my Select:: field, then I can see $data["fields"]. Code Snippet: Here's a snippet of my code:
Select::make('fields')
->label(__('forms.fields'))
->multiple()
->relationship(name: "fields", titleAttribute: "name")
->required(),
Select::make('fields')
->label(__('forms.fields'))
->multiple()
->relationship(name: "fields", titleAttribute: "name")
->required(),
Issue: $data["fields"] is not present in my action method when using ->multiple(). Expected Behavior: I expect to see $data["fields"] even when using ->multiple(). Documentation Reference: I have already read the documentation, which mentions that "multiple" options are returned in JSON format and recommends adding an array cast to the model property. I assume that it has to do something with this but for ->action, but haven't found a way to solve it. Additional Context: - I have already checked the form field name, and it matches the key used in $data. - I have added a dd($data) to check the content of $data, and the structure aligns with my expectations. If anyone has experienced a similar issue or has insights on why ->multiple() might be affecting the visibility of $data["fields"], please share your thoughts! Your help is greatly appreciated. πŸ™ Thanks in advance!
2 Replies
Dennis Koch
Dennis Kochβ€’13mo ago
I don’t think multiple() is the issue but relationship(). It tries to save the data directly to the given relationship and therefore it’s not included in the data. Try replacing it with ->options(fn () => get related options) and it should work.
LiruLiruLiru
LiruLiruLiruOPβ€’13mo ago
Sorry I didn't reply earlier. That solved the issue, thank you very much for your help and for pointing me in the right direction!!
Want results from more Discord servers?
Add your server