Angular formGroup, scroll to first Invalid input in a scrolling div

Discussão em 'Angular' iniciado por crunch, Janeiro 15, 2025.

  1. crunch

    crunch Guest

    I have a significantly large form and the way the application is laid out, the form is in a scrolling div, so I can't use (because it doesn't seem to work) something like:

    private scrollToFirstInvalidControl() {
    const firstInvalidControl: HTMLElement = this.el.nativeElement.querySelector(
    "form .ng-invalid"
    );

    firstInvalidControl.focus();
    }


    This is a one-off thing, I also don't want it as a directive, it's just overkill, I just want to focus on the first invalid object in the formGroup after I run this.form.markAllAsTouched(); and walk away.. smooth scrolling would be a nice bonus, but not a huge deal.

    Continue reading...

Compartilhe esta Página