问题
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