bouncer icon indicating copy to clipboard operation
bouncer copied to clipboard

Allow field-specific custom messages.

Open HaroldPutman opened this issue 5 years ago • 6 comments

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.

HaroldPutman avatar Dec 21 '18 19:12 HaroldPutman

This is an interesting one. Let me sit on it for a little bit.

cferdinandi avatar Dec 21 '18 19:12 cferdinandi

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 avatar Jan 08 '19 18:01 HaroldPutman

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

tbb2 avatar Jan 11 '19 11:01 tbb2

@cferdinandi , Any update on this one?

janvanhelvoort avatar Jun 25 '19 08:06 janvanhelvoort

Forked and merged here

davidangel avatar Dec 12 '19 19:12 davidangel

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

er314 avatar Aug 24 '20 16:08 er314