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
awcodes
awcodes2y ago
Use a validation for max length instead of the maxLength(). Sounds like a weird browser bug though.
Dan Harrin
Dan Harrin2y ago
tofu
BuffTofu
BuffTofuOP2y ago
@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
Dan Harrin
Dan Harrin2y ago
can you try on a different browser please? ->rule('max:512') is the backend-only equivalent
awcodes
awcodes2y ago
Those 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.
BuffTofu
BuffTofuOP2y ago
@Dan Harrin I am getting the truncate issue in Chrome, Firefox, and Safari with Filament 2.0
Dan Harrin
Dan Harrin2y ago
how very weird ive just checked its just browser default behaviour ->rule('max:512') is your way around
BuffTofu
BuffTofuOP2y ago
Yep, that does work. Thank you both
Dan Harrin
Dan Harrin2y ago
never even noticed that behaviour tbh but i think it makes sense
BuffTofu
BuffTofuOP2y ago
Yea, it was just troublesome for my users because they are copy / pasting stuff and weren't even noticing it got cut off
awcodes
awcodes2y ago
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.
Want results from more Discord servers?
Add your server