2011-12-20 13 views
0

私はjQueryツールのバリデーションで2回のサブミットを防止しようとしています。ここで使用しているonFailを使用すると問題が発生しています。何か案は?タイマー/タイムアウトを試してみましたが、それは本当にひどい解決策です。jQueryツールの検証とダブルサブミット

$("form").submit(function(){ 
    $('input[type=submit]').click(function(event){ 
     event.preventDefault(); 
    }); 
}); 

$("form").bind("onFail", function(e, errors) { 
    // we are only doing stuff when the form is submitted 
    if (e.originalEvent.type == 'submit') { 
     // loop through Error objects and add the border color 
     $.each(errors, function() { 
      var input = this.input; 
      input.stop(true).effect("shake", { times:3 }, 75); 
      input.css({borderColor: '#D94E27'}).focus(function() { 
       input.css({borderColor: '#444'}); 
      }); 
     }); 
    } 
}); 


$("form").validator({ 
    message: '<div class="errormessages"></div>', 
    position: 'center right', 
    offset: [0, 0] 
}); 
+0

は、なぜあなたは、送信ボタンを無効にするカント?障害が発生した場合に再度有効にしてください。 – Kishore

+0

は機能しません。私はちょうど上記の私のコードを更新...私は何か間違っていると確信しています... – delphi

答えて

0

ああはそれを見つけた:1を提出した後

$("form").validator({ 
    message: '<div class="errormessages"></div>', 
    position: 'center right', 
    offset: [0, 0] 
}).bind("onFail", function(e, errors) { 
    // we are only doing stuff when the form is submitted 
    if (e.originalEvent.type == 'submit') { 
     // loop through Error objects and add the border color 
     $.each(errors, function() { 
      var input = this.input; 
      input.stop(true).effect("shake", { times:3 }, 75); 
      input.css({borderColor: '#D94E27'}).focus(function() { 
       input.css({borderColor: '#444'}); 
      }); 
     }); 

    } 
}).submit(function(e) { 
    // client-side validation passed 
    if (!e.isDefaultPrevented()) { 
     $("button[type=submit], input[type=submit]").attr('disabled', true); 
    } 
});