Aurelia-Validation with array of custom objects

Having the following class:

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

    .ensure((m: MyTestClass) => m.MyArray). ???

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

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

export class MyTestClass{
      public MyArray: Tuple[];

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

    .ensure((e: Tuple) => e.Item1).required()
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.