Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HaroldPutman
Copy link

@HaroldPutman HaroldPutman commented Dec 21, 2018

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.

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`.
@cferdinandi
Copy link
Owner

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.
@HaroldPutman
Copy link
Author

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.

@tbb2
Copy link

tbb2 commented Jan 11, 2019

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

@janvanhelvoort
Copy link

@cferdinandi , Any update on this one?

@davidangel
Copy link

Forked and merged here

@er314
Copy link

er314 commented Aug 24, 2020

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 :

#39 (comment) .

It includes 2 example use cases, the 1st one being in reply to @tbb2 request #29 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants