Epko
Epko
FFilament
Created by Leepay Lon (Dmitry) on 11/6/2023 in #❓┊help
Trim each input
Added this to AppServiceProvider:
use Filament\Forms;
public function boot(): void
{
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
}
use Filament\Forms;
public function boot(): void
{
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
}
Works perfectly. Thanks for the hint @awcodes !
7 replies
FFilament
Created by Leepay Lon (Dmitry) on 11/6/2023 in #❓┊help
Trim each input
This is indeed working, and probably the best solution. I find it strange this is not the default behaviour in Filament, as it is the default behaviour in Laravel (https://laravel.com/docs/11.x/validation#a-note-on-optional-fields). For anyone having the same issue, this is how I implemented it (thanks to the suggestion of @toeknee):
protected function mutateFormDataBeforeSave(array $data): array
{
foreach ($data as $key => $value) {
$data[$key] = is_string($value) ? trim($value) : $value;
}
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
foreach ($data as $key => $value) {
$data[$key] = is_string($value) ? trim($value) : $value;
}
return $data;
}
But I have to repeat this in every Edit page.
7 replies