guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

`data-parsley-minlength-message`/`data-parsley-maxlength-message` ignored when using both `minlength` and `maxlength` #1368

Closed iamkeir closed 1 year ago

iamkeir commented 1 year ago

Using minlength and data-parsley-minlength-message, or maxlength and data-parsley-maxlength-message outputs the custom error message correctly. However, if you use both on a single field, it ignores the custom error messages and instead outputs the default message in Parsley.

See here: https://codepen.io/iamkeir/pen/mdLzXRX?editors=101

iamkeir commented 1 year ago

Interestingly, if you switch to using data-parsley-minlength/data-parsley-maxlength instead of minlength/maxlength, it works as expected.

marcandre commented 1 year ago

Thanks for the report, I completely see how this can be seen as a bug.

What's happening is that you are meant to be using data-parsley-length validator instead of data-parsley-minlength/data-parsley-maxlength. It produces a better error message.

There is no HTML5-builtin equivalent, so Parsley does that for you if you use minlength + maxlength.

I guess that Parsley could do the same for data-parsley-minlength/data-parsley-maxlength, or some odd mix of min length + data-parsley-maxlength, but I'm not convinced there's a good reason to accept that.

What I've done is made the documentation more explicit about it.

iamkeir commented 1 year ago

@marcandre thanks for fast response, and fair enough - just raising the inconsistency that caught me out.