我遇到這樣的問題一個新問題:無法刪除的驗證和應用使用jQuery驗證插件
我們正在使用jquery驗證插件進行客戶端驗證。用於初始化表單的腳本是動態生成的。表單本身也是使用jTemplates和json動態生成的。
問題是我需要重新初始化某些輸入元素的驗證並更改錯誤位置。我找不到任何可以重新驗證插件api中的驗證規則和錯誤位置的方法。
我一直試圖做這樣的事情:
下面的代碼是爲幾個對象執行(someUniqueValue從這些對象採取)。
//removing old rules.
$("input[value='someUniqueValue']").next('input:text').rules('remove');
//I have a hidden field with unique value and an input after it so the code above is ok.
$("#someForm").validate({
errorPlacement: function (error, elementToValidate) {
var $messageElement = $("[id='theExactFieldToValidate'][value='someUniqueValue']");
//error placement logic
},
rules: {
"theExactFieldToValidate": {
required: true,
maxlength: 25
}
}
});
,我想驗證我有以下各輸入之前(我想在該跨度被顯示的錯誤消息):
$("input[value='someUniqueValue']").next('input:text').rules('remove');
:執行以下後
<span id="validate-theExactFieldToValidate" class="hidden" style="display:block" value="someUniqueValue"></span>
元素失去驗證規則,但如果我嘗試應用新規則,則不會發生任何事情。
$("input[value='someUniqueValue']").next('input:text').rules()
上面的代碼只是返回一個空對象。
如何更改單獨輸入的驗證邏輯和錯誤位置?