仅当对象没有功能和模式验证时才进行敲除验证 [英] Knockout Validation onlyif object no function and pattern validation
本文介绍了仅当对象没有功能和模式验证时才进行敲除验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当标题为空时,我想要 priceMax 是必需的.
I want to the priceMax was required, when title is empty.
我有代码
self.searchParameters = {
title: ko.observable().extend({
refreshCountOffers: 500
}),
priceMax: ko.observable().extend({
required: {
onlyIf: function() {
return title==null;
}
},
refreshCountOffers: 500
})
};
,但我收到错误标题未定义".
,but I get error 'title is not defined'.
当用户输入第一个字母时,如何禁用显示模式验证错误的选项?
How to disable option, which show error for pattern validation, when user input first letter?
postCode: ko.observable().extend({
required: true,
pattern: {
message: 'Post code is not valid',
params: '[0-9]{2}-[0-9]{5}'
},
refreshCountOffers: 500
})
我的jsfiddle
推荐答案
onlyIf
检查有两个问题:
- 您需要限定
title
属性 title
是可观察的,因此您需要访问该值
- you need to qualify the
title
property title
is observable so you need to access the value
下面的代码解决了两者:
The code below resolves both:
onlyIf: function() {
return self.searchParameters.title();
}
这篇关于仅当对象没有功能和模式验证时才进行敲除验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文