我有一個表單,我通過jQuery Validate插件驗證。除了一件事以外,一切工作都很好。有條件的遠程驗證
我有一個我使用的字段,遠程規則,我使用AJAX來檢查是否已經有一個具有相同名稱的應用程序記錄。只有當用戶更改字段中的值時,我才需要執行此驗證。
這是驗證碼,我有:
$('#createapp').validate({
rules: {
appname: {
minlength: 8,
required: true,
remote: {
url: "<?php echo base_url();?>app/application/check_app",
type:"POST",
async: false,
data: {
appname: function() {
return $("#appname").val();
}
}
}
},
apptitle: {
required: true
}
},
messages: {
appname: {
remote: "Application with same name already exists"
}
},
highlight: function(label) {
$(label).closest('.control-group').addClass('error');
},
success: function(label) {
label
.text('OK!').addClass('valid')
.closest('.control-group').addClass('success');
}
});
我需要這樣做:
僅當用戶更改的應用程序名稱字段中的文本遠程驗證。我嘗試使用依賴,但無法使其工作。這基本上是我試過的:
remote: {
depends: function(element){
return ($('#appname').val() != "<?php echo trim($application[0]->app_name) ?>");
}
已經登錄這可能會幫助您:HTTP://論壇。 jquery.com/topic/jquery-validate-remote-vs-depends –
該話題3年前發佈,它說這是一個錯誤。它曾經修復過,或者我需要採取一種解決方法? – Neel
我不認爲它是固定的;現在我會採用解決方法。我在插件github頁面上找不到問題,但值得一看:https://github.com/jzaefferer/jquery-validation/issues/search?q = remote + depends –