bouncer
bouncer copied to clipboard
Allow field-specific custom messages.
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. You can specify custom messages through attributes like data-bouncer-message-wrong-length-under
to provide your own validation message for a specific field.
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-out-of-range
or data-bouncer-message-wrong-length
.
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.
Having custom messages for all types of validation errors would be very useful for me too. Example (this exists on all shop sites I guess): a form with a "I accept the terms" checkbox. The validation type just needs to be "required", but you want the error message to say "Please accept the terms to continue" instead of just "This field is required." like the other checkboxes on the site
@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 ] ) IS readily supported by the current featureset. -> See my detailed explanation here :
https://github.com/cferdinandi/bouncer/issues/39#issuecomment-679238599 .
It includes 2 example use cases, the 1st one being in reply to @tbb2 request https://github.com/cferdinandi/bouncer/pull/29#issuecomment-453490226