ng-dynamic-forms icon indicating copy to clipboard operation
ng-dynamic-forms copied to clipboard

Support for validators property as optionally type ValidatorFn[]

Open tylerthrash opened this issue 6 years ago • 1 comments

Could the validators property on the dynamic models optionally be an array of ValidatorFn? I've used Covalent dynamic forms a lot and coming from that they have

validators?: ITdDynamicElementValidator[];

as a property of the ITdDynamicElementConfig and ITdDynamicElementValidator simply being

export interface ITdDynamicElementValidator {
    validator: ValidatorFn;
}

That way all you have to do when defining the property on your model is

validators:  [ { validator: myValidator() } ],

Then in the template catch the errors with a custom error messages component to display the error messages by error message key

const controlErrors: ValidationErrors = this.errorMessagesModel.control.errors;

I found this very simple to use.

Is something like this doable, and if not, why?

Thanks!

tylerthrash avatar Sep 06 '19 21:09 tylerthrash

I'm going to start working on this and create a pull request for it. Also, I'm going to implement a way to optionally pass an error message template for each control or specific controls. This would be in addition to the current way to declare validators and display error messages. You could use one or the other, the default would be the current way it's setup.

tylerthrash avatar Dec 04 '19 21:12 tylerthrash