cferdinandi / validate

A lightweight form validation script.
MIT License
230 stars 39 forks source link

Fixed hasError to also return custom error messages #32

Open bofrede opened 7 years ago

bofrede commented 7 years ago

Error messages set by setCustomValidity was ignored.

cferdinandi commented 7 years ago

I'm not sure this will work in it's current form, since any other message other than the generic one will return first and the custom error will never surface.

bofrede commented 7 years ago

@cferdinandi Thanks for your research and articles on HTML5 forms. It's good to finally being able to use HTML5 form validation.

I agree, that the generic errors are suppressing the custom error message, but without this fix, custom error messages are always ignored. So, while this solution may not be perfect, it's still a tangible improvement.

The fields I used custom errors on have been required fields, so I didn't miss an additional error message.

michapietsch commented 6 years ago

I don't think this is a problem. I use custom errors e.g. to validate the availability of a username or email address. In this case it makes perfect sense that first of all the visitor has to enter something, secondly it has to be of valid format and only then I will tell him about availability.

I just integrated support for setCustomValidity in https://github.com/michapietsch/validate/commit/94022b047c1a66bbcbc81eeedbaa31f790ab4f92. Maybe you find it useful.