无法使用淘汰验证验证自定义组
Unable to validate a custom group using Knockout Validation
我不知道如何获得Knockout Validation插件来验证视图模型属性的自定义选择。我可以调用isValid()
来成功验证整个视图模型。
我遵循了这里列出的涵盖场景的文档,并检查了我能找到的关于堆栈溢出的所有答案。
我的代码是这样的:
function MyViewModel() {
var self = this;
self.myproperty = ko.observableArray().extend({ minLength: { message: 'You must specify at least one item.'} })
self.anotherproperty = ko.observable().extend({ required: { params: true, message: 'You must supply a value.'} });
self.IsEntireModelValid = function() {
if (!self.isValid()) {
self.errors.showAllMessages();
return false;
}
else {
return true;
}
self.IsAnotherPropertyValidOnly = function() {
var errors = ko.validation.group(self.anotherproperty);
if (errors.length > 0) {
errors.showAllMessages();
return false;
}
else {
return true;
}
}
当我调用self.IsAnotherPropertyValidOnly()
时,errors变量不包含错误,但当我调用self.IsEntireModelValid()
时,我得到正确的响应。
您需要使用errors().length
。
self.IsAnotherPropertyValidOnly = function() {
var errors = ko.validation.group(self.anotherproperty);
if (errors().length > 0) {
errors.showAllMessages();
return false;
}
else {
return true;
}
}
http://jsfiddle.net/WY7V3/2/相关文章:
- jQuery自定义验证比较多个输入的序列
- 自定义表单验证和提交
- jQuery工具验证器自定义效果-添加&消除影响
- 在 AngularJs 中验证自定义指令(我想让它成为必需的)
- jQuery验证自定义错误
- jQuery验证自定义方法规则和具有动态名称的消息
- 有没有一种更优雅、可扩展的方式可以向JQuery验证自定义方法添加多个条件
- 简单的jquery验证-自定义位置错误消息放置
- jQuery验证插件:验证自定义日期格式
- jQuery验证自定义验证器不会被触发,即使名称是正确的
- 无法使用淘汰验证验证自定义组
- HTML5表单验证自定义
- JS验证自定义规则来检查数组是否为空
- 使用jQuery表单验证自定义Ajax请求
- 当返回false时,JQuery验证自定义方法不显示
- 未定义不是函数:单元测试护照身份验证自定义回调
- 不同元素的Jquery验证自定义消息动态变化
- 添加文件之前进行验证(自定义)
- 如何使用 jQuery 验证插件验证自定义 JavaScript 对象
- 淘汰验证自定义消息模板的问题