开发者

jQuery Validation & Form Plugin

I have been working with the jQuery form plugin and the jQuery Validation plugin:

Form: http://jquery.malsup.com/form/ Validation: http://bassistance.de/jquery-p开发者_如何学运维lugins/jquery-plugin-validation/

I am trying to work with both of them to play nice toegther in terms of validate document, THEN submit using the jQuery form plugin.

Any ideas?


from the docs:

$(".selector").validate({
   submitHandler: function(form) {
    $(form).ajaxSubmit();
   }
})


According to http://malsup.com/jquery/form/#validation you can use the beforeSubmit option to provide a callback that returns true or false.

In this callback simply use the .valid() plugin method described here http://jqueryvalidation.org/valid

$(document).ready(function() {
    // jQuery Validation Plugin
    $("#myForm1").validate();

    // jQuery form Plugin
    var options = { 
        target:        '#output1',   // target element(s) to be updated with server     response 
        beforeSubmit:  validate,     // pre-submit callback 
        success:       showResponse  // post-submit callback 
    };

    // bind form using 'ajaxForm' 
    $('#myForm1').ajaxForm(options); 
});

// Return validation status from jQuery validate plugin.
function validate(formData, jqForm, options) { 
    return $('#myForm1').valid();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜