AU2 Multiple validation controllers

UPDATE: I may have figured it out but can’t test thoroughly right now.

Working through my form builder migration and I hit a spot that is stumping me. I have a control that I call a List Builder, and it utilizes a collection/list control to hold an array of custom objects. The object structure is defined by a 3rd party. A custom form can be designed using the same form layout components as the form builder with a few exceptions such as not allowing a nested list builder. I’m sure I am doing something stupid here.

The issue I’m running into is with the 2 validation controllers. There is a primary validation controller that resides on the class that handles the form and it is setup like this. This is my “global” validator

private validationController: IValidationController = resolve(newInstanceForScope(IValidationController));

When list builder control is instantiating, a new validator controller is needed only for this form control and is instantiated like this. I keep a named collection so that I can easily look them up by the form control Id.

 validationController = {
                    name: validatorName,
                    validationController: this.container.get(newInstanceOf(IValidationController)) as any 
                };

The form looks like this rendered, ignore the layout, this is early in my migration so I was just trying to get adding/removing items working.


When Clicking ‘Add’ the validation controller gets called

   let controller = this.controlFactory.getValidationController(this.id);
        const result = await controller.validate();

During debug inspection, I can see the objects on that controller are the 5 form elements defined for that form

The one I instantiate as global only has the listbuilder control as it should.

When I actually call validate, it is validating both controllers. item 6 and 7 are defined on the global controller.

Hi @elitemike! Without seeing much code, my assumption is that the rules are defined on a shared object, and as the .validate() does not provide an explicit instruction on what to validate, the rule discovery infra validates all rules for all registered objects. It would be easier to troubleshoot if you could share a minimal reproduction.

I still haven’t had a chance to revisit this project, but saw that you replied and didn’t want to ignore you.

I think what the issue was/is the position of the .on(object) in the rule. In au1 it was at the end and I forgot to update this control due to the timespan between me working on this project. I also switched the ensure to be an arrow function expression which I doubt makes a difference.

The arrow function to specify the properties should not make any difference other than type-checking. The .on(object) need to be before specifying any rule though.

1 Like

Might be a good idea to call that out in the migration guide. AU1 allowed this. The AU1 docs show it at the end. I’m assuming for most people it won’t cause any issues.

The migration guide already mentions this: Migration Guide & Breaking Changes | The Aurelia 2 Docs :slight_smile:

1 Like

Alright, so this is just my .02 this Migrating to Aurelia 2 | The Aurelia 2 Docs should probably be combined with the breaking changes. I went there first before commenting lol

1 Like