ericelliott / h5Validate

An HTML5 form validation plugin for jQuery. Works on all major browsers, both new and old. Implements inline, realtime validation best practices (based on surveys and usability studies). Developed for production use in e-commerce. Currently in production with millions of users.
576 stars 125 forks source link

Validating hidden elements, overriding not working. #25

Closed tmikaeld closed 12 years ago

tmikaeld commented 12 years ago

Hi,

I'm having trouble overriding the :visible setting, since i need to validate a hidden select element.

Setting a new setting to:

Does not work.

Setting a new setting to:

Does not work.

Changing the default code to:

Works.

A better way to override this without changing the plugin code would be great.

ericelliott commented 12 years ago

Please post a test case to jsfiddle.net so I can see what's really going on in your code. h5Validate does support overrides. It's likely that you're trying to do it wrong.

tmikaeld commented 12 years ago

Instructions in the fiddle: http://jsfiddle.net/aKpha/

Included one of the not working overrides.

ericelliott commented 12 years ago

Yeah, now that I've had a chance to take a closer look, you're absolutely right. The allValid default setting was contributed code that I did not look at closely enough. The problem is that configuration is stored in the closer that is only available from within the initial call to .h5Validate();

This is fine for most cases, because h5Validate properly stores and passes data through its event handlers. However, since allValid is available as a direct function call, rather than as a triggered event, the bound settings are ignored and a new instance of h5Validate gets created. This is actually true for all of the callable methods. The only one that is instance safe is 'isValid', because it now uses the 'validate' event internally.

tmikaeld commented 12 years ago

Glad you made some sense of my fiddle :-)

Yeah, i'm using isValid per field right now, it's quite cumbersome for a large form though ;-)

ericelliott commented 12 years ago

I'll have a fix for you, soon. Just have to squeeze it between my already hectic work and book writing schedules. =)

tmikaeld commented 12 years ago

No need to stress Eric, i can manage with this current solution until you have time and lust to do it.

When i'm done with this project, i will try and learn more of jquery and javascript so i can help you.

Thanks for you'r time, really apeciate it.

ericelliott commented 12 years ago

Fixed in commit 2583d90