I have an odd requirement and was hoping for some help.
I need to focus on the first found invalid input of a form after clicking a button (not submit). The form is rather large, and so the screen needs to scroll to the first invalid input.
This AngularJS answer would be what I would need, but didn't know if a directive like this would be the way to go in Angular 2:
Set focus on first invalid input in AngularJs form
What would be the Angular 2 way to do this? Thanks for all the help!
Plain HTML solution. If you don't need to be scrolling , just focus on first valid input, I use :
This is for template driven form here. We focus on second element of invalidFields cuz first is the whole form which is invalid too.
For Angular Material , The below worked for me
Unfortunately I can't test this at the moment, so might be a few bugs, but should be mostly there. Just add it to your form.