jQuery validation quirk - blocking submit -



jQuery validation quirk - blocking submit -

my submit button beingness blocked if required field triggered. if fill in, have click outside input validate field again, thusly having press submit twice.

any ideas if it's submit handler causing this?

// form // validate enquiry form var product_form = jquery('#product_enquiry_form'); jquery(product_form).validate({ onkeyup: true, submithandler: product_enquiry_submit, errorelement: 'div', wrapper: false, errorplacement: function(error, element) { error.insertbefore(element); // default function } }); // submit enquiry function product_enquiry_submit(){ jquery.ajax({ type: 'post', url: jquery(product_form).attr( 'action' ) + '?ajax=true', datatype: 'text', data: jquery(product_form).serialize(), success: function(data){ if (data == 'success') { jquery(product_form).fadeout(400, function() { jquery('.message-sent').slidedown(400); }); } else if (data == 'badcode') { // robot submitting honeypot } else { alert('message not sent, please seek again.'); } } }); }

a collection of issues causing problem.

1) var product_form = jquery('#product_enquiry_form');

your product_form variable contains jquery(), when it's referenced, don't need wrap within jquery() again. you've done in several places.

jquery(product_form).validate({ ...

this sufficient...

product_form.validate({ ...

2) true not valid value onkeyup. alternative enabled default setting true break things. set false or function. otherwise, leave out. see: http://jqueryvalidation.org/validate/#onkeyup

3) wrapper alternative supposed "string" represents html element li, etc., not boolean false. if don't need wrap label elements, leave alternative out. see: http://jqueryvalidation.org/validate/#wrapper

otherwise, code appears working fine:

demo: http://jsfiddle.net/hrt4c/

jquery jquery-validate

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -