F
Filament15mo ago
Bumpyy

Default value for Settings page form

I'm using the Spatie Settings plugin but some input need to be able to be empty, the problem is that the page will display error if some input have no data, is there an easy way to save value to empty string if user input no data, other than using lifecycle hook (i'm using mutateFormDataBeforeSave, but it's a pain if the page have many form) ?
Solution:
in the end i'm using array_map in mutateFormDataBeforeSave protected function mutateFormDataBeforeSave(array $data): array { //? Loop through data and check if there's null value then replace it with empty string....
Jump to solution
3 Replies
DrByte
DrByte15mo ago
Have you tried adding ->nullable() to the form's input component?
Bumpyy
BumpyyOP15mo ago
According to the documentation "The field value can be empty. This rule is applied by default if the required rule is not present" so i guess that's not it.
Solution
Bumpyy
Bumpyy15mo ago
in the end i'm using array_map in mutateFormDataBeforeSave protected function mutateFormDataBeforeSave(array $data): array { //? Loop through data and check if there's null value then replace it with empty string. $data = array_map(function ($value) { return $value === null ? "" : $value; }, $data); return $data; }
Want results from more Discord servers?
Add your server