如何使breezejs必需的验证器允许空字符串 [英] how to make the breezejs required validator allow empty strings
本文介绍了如何使breezejs必需的验证器允许空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在breezejs中允许在必需属性中使用空字符串的首选方法是什么?
What is the preferred way in breezejs to allow empty strings in required properties?
我发现 此答案 ,它建议替换所需的验证器,如下所示:
I found this answer which recommends replacing the required validator like this:
Validator.required = function (context) {
var valFn = function (v, ctx) {
return v != null;
}
return new Validator("required", valFn, context);
};
// register the new validator so that metadata can find it.
Validator.registerFactory(Validator.required, "required");
在某处还提到了 allowEmptyStrings
标志。
执行此操作的首选方法是什么?
What is the preferred way to do this?
推荐答案
您可以创建一个必需的验证器,该验证器允许像这样的空字符串:
You can create a 'required' validator that allows empty string like this:
var v0 = Validator.required({ allowEmptyStrings: true });
这篇关于如何使breezejs必需的验证器允许空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文