Question

I am working on a projected where I need to use custom property validation rules on a client. I am using breeze version 1.3.6. When I specify more than one rule I am running into the following problem. Lets' say I have a decimal field with minValue (min value = 5) and maxValue (max value = 10) custom rules defined. When I write value 11 I am breaking maxValue rule and entityAspect.getValidationErrors returns one error. When I delete one character so the value is now 1 I am breaking the minValue rule. The problem is entityAspect.getValidationErrors returns two errors. It says that both the maxValue and minValue rules are broken. When debugging I came accros a function in breeze.debug.js version 1.3.6 line 3639:

// called from defaultInterceptor.
proto._validateProperty = function (value, context) {
    var ok = true;
    this._processValidationOpAndPublish(function (that) {
        context.property.validators.forEach(function (validator) {
            ok = ok && validate(that, validator, value, context);
        });
    });
    return ok;
};

From what I can work out it is supposed to go through all the validation rules. The problem is it stops calling validate after it hits a rule that breaks:

ok = ok && validate(that, validator, value, context);

Once 'ok' is false because one rule is broken all the remaining rules do not run so even if the are no longer broken the errors won't be cleared. I would expect all the validation rules to run to clear the errors that are no longer relevant.

Was it helpful?

Solution

Oops. That is a mistake. Should be ok = validate(...) && ok; We'll fix it. Thanks for finding and reporting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top