F
Filament8mo ago
jals65

TextInput default value on edit page

Hi, I want to set a default value on a form text input. I'm adding the ->default('some default string') property but it only works on Create, in the edit it doesn't works even though the value is empty or null. For example, I need this for when I add a new field to the form and for example a user accesses the form when they had previously saved it. So that this field appears already filled in with the default value.
Solution:
You have many way to do that and you have choose the proper one according to your scenario: - Use mutator in your Eloquent as @PovilasKorop said. - Use ->mutateFormDataUsing() chain or mutateFormDataBeforeSave() lifecycle method. - If you need to show the default value to the user, you can use ->formatStateUsing() and in the callback, check if the $state is null then return you default value...
Jump to solution
4 Replies
Povilas K
Povilas K8mo ago
I would save that value in the database on Eloquent level, with mutator
jals65
jals65OP8mo ago
The problem is that I saved the form as json in a field, it is not directly related to a mysql field that can use the mysql default
Solution
MohamedSabil83
MohamedSabil838mo ago
You have many way to do that and you have choose the proper one according to your scenario: - Use mutator in your Eloquent as @PovilasKorop said. - Use ->mutateFormDataUsing() chain or mutateFormDataBeforeSave() lifecycle method. - If you need to show the default value to the user, you can use ->formatStateUsing() and in the callback, check if the $state is null then return you default value
jals65
jals65OP8mo ago
ok, i'm going to try it
Want results from more Discord servers?
Add your server