Disabled select field with default not taken into account when creating record

Hi! πŸ‘‹ I've just upgraded to Filament v3 and the experience is amazing so far! πŸ˜„ Only one little hiccup: one of my select fields doesn't work anymore (probably because I didn't really searched for how it works under the hood...) Here is my field definition:
Forms\Components\Select::make('team_id')
->label(__('Team'))
->relationship('team', 'name')
->default(Auth::user()?->currentTeam?->id)
->disabled()
->required()
Forms\Components\Select::make('team_id')
->label(__('Team'))
->relationship('team', 'name')
->default(Auth::user()?->currentTeam?->id)
->disabled()
->required()
It allows the user to see which team the record is going to be created under. Saving the record into the database fails because the insertion isn't provided with the team_id. It worked on v2 for some reason. Is there an "idiomatic" way to make it work? I can just force it into the insertion query of course but wanted to know if there was a "better" way. Also, if it's disabled, could the user forge a request modifying it or it's fine without a check on my end? Note: this field is in a wizard and it doesn't work without the ->relationship either.
3 Replies
Arnaud Lier
Arnaud LierOPβ€’2y ago
Workaround for the moment in the Create page:
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['team_id'] = auth()->user()?->currentTeam?->id;

return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['team_id'] = auth()->user()?->currentTeam?->id;

return $data;
}
Patrick Boivin
Patrick Boivinβ€’2y ago
I think this is normal... in a regular HTML form, disabled fields are not included in the request. Your solution is pretty good, because the data is sensitive and shouldn't be modified by a clever user with the browser dev tools.
Arnaud Lier
Arnaud LierOPβ€’2y ago
I would've hoped Filament would inject those but eh, fair enough. I wonder why it worked with Filament 2 though!

Did you find this page helpful?