jquery tools .onSuccess -
can point me in right direction on this? using tools validator wanting execute ajax submit function have if validation passes. have working validation script here works, , ajax call works; i'm having time trying figure out how them work together.
how can this?
$(document).ready(function() { $("#leadbanker_intake_form").validator({ position: 'center right', offset: [0, 0], message: '<div><em/></div>' }).bind("onsuccess", function(e, els) { // function here still works though forms haven't validated } });
as per the documentation:
the second argument jquery object containing fields passed validation.
so, in onsuccess
callback, need check length
of els
(the second argument) , make sure it's equal total number of fields you're validating.
i think should work (but haven't tested it):
$(document).ready(function() { $("#leadbanker_intake_form").validator({ position: 'center right', offset: [0, 0], message: '<div><em/></div>' }).bind("onsuccess", function(e, els) { var numsucceeded = els.length, numexpected = $(this).data('validator').getinputs().length; if (numsucceeded === numexpected) { // ajax on } } });
edit: in comment below, said if use code:
$(document).ready(function() { $("#leadbanker_intake_form").validator({ position: 'center right', offset: [0, 0], message: '<div><em/></div>' }).bind("onsuccess", function(e, els) { var numsucceeded = els.length, numexpected = $(this).data('validator').getinputs().length; if (numsucceeded === numexpected) { $("#leadbanker_intake_form").submit(function() {} } } });
then code seems ignored. see 2 problems that.
first, code syntactically incorrect - you're missing 2 close parens (the code on question missing one, , forgot add 1 in). fix syntax, code should this:
$(document).ready(function() { $("#leadbanker_intake_form").validator({ position: 'center right', offset: [0, 0], message: '<div><em/></div>' }).bind("onsuccess", function(e, els) { var numsucceeded = els.length, numexpected = $(this).data('validator').getinputs().length; if (numsucceeded === numexpected) { $("#leadbanker_intake_form").submit(function() {}); // <-- here } }); // <-- , here });
note semicolons missed well. i'm not sure if these syntax errors exist in actual code you're trying run, or if transcription error on part, it's serious enough syntax error break whole thing.
the other problem .submit(...)
call binds submit listener, if form validated. - , i'm not sure of part - form may have submitted time bind submit
handler. solution problem bind listener outside of onsuccess
callback. other possibility regarding (i need read on jquery tools docs...) need manually submit form - is, might binding handler, but form's never submitting!
i can't more without looking tools docs, , maybe actual code well. if suggestions in edit don't fix problem you, mind posting jsfiddle or jsbin reproduces problem?
Comments
Post a Comment