ajaxForm с использованием проверки Spry - PullRequest
0 голосов
/ 14 июля 2011

Я пытаюсь использовать проверку spry с ajaxForm.Проблема в том, что я не думаю, что моя принудительная проверка spry во время beforeSubmit находит форму.Я не получаю никаких ошибок, похоже, что beforeSubmit не запускается, потому что не может найти форму, "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 ]

1 голос
/ 13 ноября 2011

Я не большой программист, но это было мое решение:

    // 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');
            }

    });
0 голосов
/ 10 июля 2012

Попробуйте это ..

$("#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();
            } 
        });
...