Aurelia-Validation with array of custom objects

Having the following class:

export class MyTestClass{
      public MyArray: {Item1: string, Item2: string}[];
}

ValidationRules
    .ensure((m: MyTestClass) => m.MyArray). ???
    .on(MyTestClass);

How can I create a validation rule for each element of “MyArray” with “Item1” and “Item2”?

Update
Tried to create a sub-class, but it doesn’t work:

export class MyTestClass{
      public MyArray: Tuple[];
}

export class Tuple{
    Item1: string;
    Item2: string;
}

ValidationRules
    .ensure((e: Tuple) => e.Item1).required()
    .on(Tuple);
1 Like

So, I found the issue.

Using the subclass works well. My issue was, that I still instantiated the array with

MyArray.push({Item1: null, Item2: null})"...

I guess this led to the fact that the class didn’t get instantiated and following the ValidationRules didn’t get applied.

Now, adding elements to the array by

MyArray.push(new Tuple());

solved the issue.