2
jQuery.validate停止提交表單。我希望它只是向用戶顯示錯誤,但允許他們提交。jQuery.validate停止提交表單
我正在使用ASP MVC附帶的jquery.validate.unobtrusive庫。
我使用jquery.tmpl動態創建表單,然後使用jquery.datalink將輸入字段鏈接到頁面上的json對象。所以我的文檔準備就緒看起來像這樣。
jQuery(function ($) {
// this allows be to rebind validation after the dynamic form has been created
$("form").removeData("validator");
$("form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse($("form"));
// submit the answers
$("form").submit(function(e) {
$("input[name=jsonResponse]").val(JSON.stringify(answerArray));
return true;
});
}
我注意到,有一個選項
$("form").validate({ onsubmit: false });
,但似乎殺死所有驗證。
所以只是爲了回顧當我的表單呈現時,我想立即顯示所有錯誤,但我不想阻止提交工作。