Angular 2 Reactive Forms trigger validation on submit

Discussão em 'Angular' iniciado por arvstracthoughts, Abril 16, 2025.

  1. is there a way that all validators of a reactive forms can be triggered upon submit and not only by the "dirty" and "touch" events?

    The reason for this is we have a very large forms which doesn't indicate if a field is required or not, and user might miss some of the required control, so upon submit, it is expected that all of the invalid fields which are missed by the end user will be shown.

    I have tried marking the form as "touched" by using the

    FormGroup.markAsTouched(true);


    it worked, and so I also tried marking it as "dirty"

    FormGroup.markAsDirty(true);


    but the css of the class is still "ng-pristine",

    Is there a way to trigger it manually from the component, I tried googling it to no avail, thanks you in advance!

    UPDATE

    I already got it working by iterating the FormGroup.controls and marking it as "dirty", but is there a "standard" way to do this.

    Continue reading...

Compartilhe esta Página