2012-01-27 10 views
0

私は、検証とAJAXリクエストを含むWebフォームをバックグラウンドで構築しています。私の問題は、すべての検証が正しく行われた後に、送信ボタンにアニメーションのみを実行させたいということです。jQueryは検証後にのみアニメーションを実行します

//jQuery ANIMATION 
$("#submit1").click(function(){ 
    $("#initial_form").animate({"left": "-=750px",opacity: 0.25,}) .fadeOut(1); 
    $("#ipad_congratulations").delay(500) .fadeIn("slow"); 
}); 

//VALIDATION 
<script type="text/javascript"> 
     /* <![CDATA[ */ 
     jQuery(function(){ 
      jQuery("#firstname").validate({ 
       expression: "if (VAL) return true; else return false;", 
       message: "<br /> First name please." 
      }); 
      jQuery("#lastname").validate({ 
       expression: "if (VAL) return true; else return false;", 
       message: "<br />Last name too." 
      }); 
      jQuery("#ValidNumber").validate({ 
       expression: "if (!isNaN(VAL) && VAL) return true; else return false;", 
       message: "Please enter a valid Zip Code" 
      }); 
      jQuery("#ValidInteger").validate({ 
       expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return false;", 
       message: "Please enter a valid integer" 
      }); 
      jQuery("#ValidDate").validate({ 
       expression: "if (!isValidDate(parseInt(VAL.split('-')[2]), parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false; else return true;", 
       message: "Please enter a valid Date" 
      }); 
      jQuery("#usremail").validate({ 
       expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;", 
       message: "<br />Please enter a valid Email Addres" 
      }); 
      jQuery("#ValidPassword").validate({ 
       expression: "if (VAL.length > 5 && VAL) return true; else return false;", 
       message: "Please enter a valid Password" 
      }); 
      jQuery("#ValidConfirmPassword").validate({ 
       expression: "if ((VAL == jQuery('#ValidPassword').val()) && VAL) return true; else return false;", 
       message: "Confirm password field doesn't match the password field" 
      }); 
      jQuery("#ValidSelection").validate({ 
       expression: "if (VAL != '0') return true; else return false;", 
       message: "Please make a selection" 
      }); 
      jQuery("#ValidMultiSelection").validate({ 
       expression: "if (VAL) return true; else return false;", 
       message: "Please make a selection" 
      }); 
      jQuery("#ValidRadio").validate({ 
       expression: "if (isChecked(SelfID)) return true; else return false;", 
       message: "Please select a radio button" 
      }); 
      jQuery("#resident").validate({ 
       expression: "if (isChecked(SelfID)) return true; else return false;", 
       message: "" 
      }); 
      jQuery("#terms").validate({ 
       expression: "if (isChecked(SelfID)) return true; else return false;", 
       message: "" 
      });     
     }); 
     /* ]]> */ 
    </script> 

$(function(){ 
     $('#form').form({ 
      success:function(data){ 
       $.messager.alert('Info', data, 'info'); 
      } 
     }); 
    }); 
    </script> 
+0

検証はどこですか? –

答えて

1

あなたの検証構造は少し仕事を使用することができます。

代わりに独自の機能で、各フィールドを検証する次のように、フォーム内のすべてのフィールドを検証する検証プラグインを使用することができますが:

$('#yourForm').validate({ 
    rules: { 
     field1: required, 
     field2: { 
      required: true, 
      email: true 
     } 
    }, 
    messages: { 
     field1: 'Field 1 error message.', 
     field2: 'Field 1 error message.' 
    } 
}); 

上記は、原油の例で、見ています詳細および例についてはdocumentationを参照してください。

あなたの検証ルールを設定したら、その後、次のようにフォームが有効であるかどうかのロジックを適用することができます。

$('#yourForm').submit(function(){ 

    // If the form is NOT valid, stop. 
    if (!$('#yourForm').valid()) return false; 

    // The form is valid, so play the animation 
    // ... $('#foo').animate(); 
}); 

は、この情報がお役に立てば幸いです。

+0

私は解決策を見つけるのを助けてくれてありがとう。 – Mountaininja

関連する問題