Aurelia validation does not work for derived classes

I have the following script in typescript 1.6 and the latest aurelia:

import {ensure, Validation} from "aurelia-validation";
import {ValidationGroup} from "aurelia-validation";

@inject(Validation)
export class BaseClass {

  validation: ValidationGroup;

  @ensure(function (it) { it.isNotEmpty().hasLengthBetween(3, 10) })
  firstName: string;

  constructor(validation: Validation) {
    this.validation = validation.on(this, null);
  }
}

@inject(Validation)
export class DerivedClass extends BaseClass {

  @ensure(function (it) { it.isNotEmpty().hasLengthBetween(3, 10) })
  lastName: string;

  constructor(validation: Validation) {
    super(validation);
  }

  submit() {
    this.validation.validate().then((value) => { /* */ });
  }
}

The problem is that when you submit form data in a view from a derived-class.htmlproperty, it lastNamereceives a confirmation, and the property firstNameis not even specified in the validation group.

+4
source share

Source: https://habr.com/ru/post/1608632/


All Articles