1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Reactive forms: mark dirty all controls in form group

Discussão em 'Angular' iniciado por hofshteyn, Setembro 12, 2024.

  1. hofshteyn

    hofshteyn Guest

    I have Angular 6 app with form. Here is an examle

    export class ExampleComponent implements OnInit {
    form: FormGroup;

    constructor(private fb: FormBuilder) { }

    ngOnInit() {
    this.form = new FormGroup({
    first: new FormControl(),
    last: new FormControl()
    });

    this.markControlsAsDirty(this.form);
    }

    markControlsAsDirty(form: FormGroup) {
    this.form.get('first').markAsDirty();
    this.form.get('last').markAsDirty();
    }
    }


    I don't want to get a single control and mark every field. Can I mark all controls in form group as dirty?

    UPDATE I've been added stackblitz example to show that two previous answers were wrong

    Continue reading...

Compartilhe esta Página