ajaxForm使用Spry验证

时间:2011-07-14 17:19:21

标签: jquery ajaxform spry

我正在尝试使用ajaxForm进行spry验证。问题是我不认为我在beforeSubmit找到表单时强制进行spry验证。我没有得到任何错误,似乎之前提交没有解雇,因为它无法找到表单,“form1”

$("#form1").ajaxForm({
        url: "processPhoneEdit.php",
        beforeSubmit: function(){
            if (Spry) { // checks if Spry is used in your page
                var r = Spry.Widget.Form.validate(form1); // validates the form
                    if (r) 
                        alert("testing");
                        return (r);

            } 
        },
        success: alert("success"),
        complete: alert("complete")
});

2 个答案:

答案 0 :(得分:1)

我不是一个程序员,但这是我的解决方案:

    // Submit button is clicked
    $("#submitShipment").click(function () 
    {

        // Spry validation:  if true
        if (Spry.Widget.Form.validate(form1) == true)
            {

                // opens the Please Wait dialog
                $('#dialogPleaseWait').dialog('open');
                // disables the submit button
                $('#submitShipment').button('disable');
                // Posts form to callback page, serializes the form into a URL string and waits for a result (success / fail)
                $.get("callbacks/insertShipment.asp", $("#form1").serialize(), insertCallback);

            } 
            else  // Spry validation:  if false
            {
                // opens jQuery UI dialog to inform user Validation failed
                $('#dialogDespatchValFail').dialog('open');
            }

    });

答案 1 :(得分:0)

试试这个..

$("#form1").ajaxForm({
            target:'#some_div',
            url:'processPhoneEdit.php',
            clearForm: 'true',
            beforeSubmit: function(formData, jqForm, options){
            if (Spry) { // checks if Spry is used in your page
                r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
                if (!r) {
                    return r;
                }
            }
            if(r)   {
                $('#submit').attr({
                    'disabled':'disabled',
                    'value':'Processing. Please Wait...'
                });     
            }
            },
            success: function() {
                $('#form1').hide();
            } 
        });