F
Filament9mo ago
HeyWeb

validationMessages not work

Forms\Components\TextInput::make('codpos')->numeric()->integer()->maxLength(5) ->validationMessages([ 'maxLength' => 'La longitud del campo es incorrecta' ]),
No description
Solution:
Forms\Components\TextInput::make('codpos')->numeric()->integer()->maxLength(5) ->validationMessages([ 'max_digits' => 'La longitud del campo es incorrecta' ]),...
Jump to solution
4 Replies
HeyWeb
HeyWebOP9mo ago
Resuelto
Solution
HeyWeb
HeyWeb9mo ago
Forms\Components\TextInput::make('codpos')->numeric()->integer()->maxLength(5) ->validationMessages([ 'max_digits' => 'La longitud del campo es incorrecta' ]),
Povilas K
Povilas K9mo ago
I just tried to reproduce, worked well for me:
Forms\Components\TextInput::make('phone_number')
->numeric()
->integer()
->maxLength(5)
->validationMessages([
'max_digits' => 'Something'
]),
Forms\Components\TextInput::make('phone_number')
->numeric()
->integer()
->maxLength(5)
->validationMessages([
'max_digits' => 'Something'
]),
So I guess the problem is not in Filament itself but in somewhere else where you store validation lang maybe, in the Laravel /lang folder? Or maybe you need to update your Filament/Laravel?
No description
Bob Gann
Bob Gann8mo ago
The key in the array in validationMessages must match the value in the laravel documentation. This is not always obvious. For maxLength - the value is "max_digits". So the message should be 'max_digits' => 'La longitud del campo es incorrecta'. Sometimes it matches - like requiredIf - is required_if. I spent 2+ hours in the debugger figuring this out. Would be happy to update the documentation - but I don't know how to contribute there.

Did you find this page helpful?