我正在使用knockout.js 验证插件,它可以完美地验证我正在使用的表单,但是,它似乎没有跟踪错误的数量。当我提交表单时,如果它检测到任何错误,它不应该提交,但它正在提交。
function EntryViewModel(fullName, addressLine1, addressLine2, city, state, ZIP, email) {
//viewmodel code here
//the validation messages are being set on my form so i figure listing all of the rules is not necessary
self.submitOrder = function(){
alert(EntryViewModel.errors().length); //displays 0
if (EntryViewModel.errors().length == 0) {
//submit
}
else{
alert('Please fix errors before submitting');
}
}
}
EntryViewModel.errors = ko.validation.group(EntryViewModel); //I also tried putting this in my viewmodel and it didn't do anything
我可能完全错误地处理了这个问题,我只是基于这个从项目的 Github 页面链接的小提琴