maxLength() to show error instead of cutting off text
Right now, with maxLength(512) on a TextInput, if I paste text that is more than 512 characters, it chops the text to 512 and shows no error to the user. This has caused some of my users to post content that is being cut off without realizing. Is there a way to show an error to the user?
11 Replies
Use a validation for max length instead of the maxLength(). Sounds like a weird browser bug though.
@awcodes what you mean by use the validation? I only am seeing this for maxLength() on the docs:
TextInput::make('name')
->minLength(2)
->maxLength(255)
And in the Validation docs, I see nothing about length of string
I'm using Filament v2
I suppose I could write a custom Laravel rule for it
can you try on a different browser please?
->rule('max:512')
is the backend-only equivalentThose two methods add the 'min-length' and 'max-length' attributes to the input, which for some reason your browser is using to truncate the text instead of treating it as a validation, so you can use the
->rules(['min:2', 'max:255'])
method directly to create a validation for the field with laravel's built in validation rules.@Dan Harrin I am getting the truncate issue in Chrome, Firefox, and Safari with Filament 2.0
how very weird
ive just checked
its just browser default behaviour
->rule('max:512')
is your way aroundYep, that does work. Thank you both
never even noticed that behaviour tbh
but i think it makes sense
Yea, it was just troublesome for my users because they are copy / pasting stuff and weren't even noticing it got cut off
Yea. That’s why I’m surprised the browser is doing it. It used to throw a validation error. Not sure when they all changed it.