2012-04-20 11 views
1

私はjQuery Validation pluginにシンプルなフェードトランジション(例:fadeToggle();)を適用しようとしていましたが、運が無かったのです。ここに私のコード:jQueryに単純なフェードトランジションを適用するにはどうすればよいですか?

$.validator.setDefaults({ 

    // Add fadeToggle(); to showErrors 
}); 

$("#login_form").validate(); 

$("#login_form").submit(function(event) { 
    event.preventDefault(); 

    if($("#login_form").valid()) { 

     $.post("/user/ajax_login", $('#login_form').serialize(), function(data) { 
      if(data.redirect != null) { 
       window.location.replace(data.redirect); 
      } 
     },'json'); 
    } 
}); 

このフェードトランジションを追加する簡単な方法はありますか?

答えて

2

非常に単純な答えの場合:

あなたはすでにそれを使用していない理由は、エラーかどうか...がありますかどうかを確認するためにvalid()メソッドを使用していますか?例えば

if($('#login_form').valid()) { 
    // everything seams fine, lets submit the form 

    $.post("/user/ajax_login", $('#login_form').serialize(), function(data) { 
     if(data.redirect != null) { 
      window.location.replace(data.redirect); 
     } 
    },'json'); 
} 
else { 
    // there is some kind of validation error 

    $('label.error') 
    .hide() // by this time all .error classes are shown, let's hide them 
    .fadeIn('slow'); // and show them gently... 

} 

Live example on JsBin

関連する問題