F
Filamentā€¢6mo ago
vkDas

Saving null while disabling a select field

Hello there, I am using a select field. When the admin is logged in, admin can choose a user. However, for a regular user login, they cannot choose a user. Instead, I am passing the logged-in username with the 'disabled' attribute. But when I am saving the record, it is becoming null. Please help me to fix this issue. code Select::make('user_name') ->options($users) ->disabled($userIsUser) ->default($userIsUser ? $loggedInUserName : '') ->searchable() ->required(!$userIsUser),
Solution:
Disabled fields aren't saved to DB. Use mutateFormDataBeforeSave() to modify data before saving it. https://filamentphp.com/docs/3.x/panels/resources/editing-records#customizing-data-before-saving...
Jump to solution
2 Replies
Solution
Dennis Koch
Dennis Kochā€¢6mo ago
Disabled fields aren't saved to DB. Use mutateFormDataBeforeSave() to modify data before saving it. https://filamentphp.com/docs/3.x/panels/resources/editing-records#customizing-data-before-saving
vkDas
vkDasā€¢5mo ago
Thank you it is working finešŸ¤©