-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow field-specific custom messages. #29
base: master
Are you sure you want to change the base?
Conversation
Override message with specific text for a particular field. For example instead of "Please lengthen this text to 50 characters or more. ..." you might want "You'll never get the job with a resume less than 50 characters long." Works for **all** validation errors. The current behavior of `data-bouncer-message` is preserved - it only effects `patternMismatch` errors. But if you specify a JSON object that looks like the messages array you can override any of the validation messages. Also made it so you can set `outOfRange` or `wrongLength` to a single string if you want the same message for both edge cases. This works in both `settings.messages` and `data-bouncer-message`.
This is an interesting one. Let me sit on it for a little bit. |
After further review, I think I prefer individual attributes to using JSON. * In most cases you only want to change one of the messages. * While not uncommon, JSON for attribute values feels like a bad mix of markup and code. * In my particular case it is easier to manage as a single attribute rather than JSON.
After further review, I think I prefer individual attributes to using JSON.
|
Having custom messages for all types of validation errors would be very useful for me too. |
@cferdinandi , Any update on this one? |
Forked and merged here |
Hi, Actually, the ability to configure custom error message per [ field + constraint-type ] (instead of only per [ constraint-type ] ) It includes 2 example use cases, the 1st one being in reply to @tbb2 request #29 (comment) |
Override message with specific text for a particular field. For example instead of "Please lengthen this text to 50 characters or more. ..." you might want "You'll never get the job with a resume less than 50 characters long."
Works for all validation errors. The current behavior of
data-bouncer-message
is preserved - it only effectspatternMismatch
errors. You can specify custom messages through attributes likedata-bouncer-message-wrong-length-under
to provide your own validation message for a specific field.Also made it so you can set
outOfRange
orwrongLength
to a single string if you want the same message for both edge cases. This works in bothsettings.messages
anddata-bouncer-message-out-of-range
ordata-bouncer-message-wrong-length
.