how to make the breezejs required validator allow empty strings

℡╲_俬逩灬. 提交于 2020-01-04 19:55:33

问题


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");

There's also mention of a allowEmptyStrings flag somewhere.

What is the preferred way to do this?


回答1:


You can create a 'required' validator that allows empty string like this:

var v0 = Validator.required({ allowEmptyStrings: true });


来源:https://stackoverflow.com/questions/23478929/how-to-make-the-breezejs-required-validator-allow-empty-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!