validation-errors.bind="errors"
but when the page loads, this array is empty. This means the user can submit it right away.
validation-errors.bind="errors"
: the array is filled correctly initially
You can make controller.errors observable, a bit of a hack IMHO, or, the currently proposed best method is to implement your own ValidationRenderer whose render method is invoked whenever validation occurs.
There is a long unresolved discussion of this, here: aurelia/validation#318
Feel free to add your support to implementing something there....
errors
property
errors
properties (yours or the controller's) helps you know when validation has occurred, nor in knowing whether the entire form is valid.
I tried changing the code to this:
this.validator.validateTrigger = validateTrigger.changeOrBlur;
/*ol.getObserver(this.todo, 'title').subscribe(() => {
this.validate();
});*/
But this has no effect: this.validator.validateObject
is never called. Maybe I am missing something to correctly use trigger with Validator?
controllerFactory.createForCurrentScope()
Validator
, containing the instance of StandardValidator
that you got from DI....
@dkent600 this could be the way! I am trying to implement it:
class MyValidator {
constructor(validator, cb) {
this.validator = validator;
this.cb = cb;
}
validateProperty(object, propertyName, rules) {
this.validator.validateProperty(object, propertyName, rules);
}
validateObject(object, rules) {
return this.validator.validateObject(object, rules).then(results => {
this.cb(results);
return results;
});
}
ruleExists(rules, rule) {
return this.validator(rules, rule);
}
}
sadly I get a strange error:
Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined
at ValidationController.processResultDelta (validation-controller.js:243)
at eval (validation-controller.js:190)
Don't see why.
constructor(authService: AuthService, controller: ValidationController) {
// Aurelia-Authentication
this.authService = authService;
this.authService.authenticated = false;
// Aurelia-Validation
this.controller = controller;
this.controller.validateTrigger = validateTrigger.change;
....