S
S
snater2013-11-25 14:01:05
JavaScript
snater, 2013-11-25 14:01:05

How to scroll a window to the first invalid input in AngularJS?

A common behavior for long forms - when the submit button is clicked - is to show the user erroneously filled fields and scroll the document to the first such field.
How can this behavior be implemented in AngularJS without using jQuery?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Meketyuk, 2014-02-02
@snater

var firstInvalidInput = angular.element(".ng-invalid")[0];
- get the first invalid input.
And scroll by the method that the user indicated above.

D
Dmitry Sidorov, 2013-11-25
@Doomsday_nxt

element.scrollIntoView(alignWithTop);

A
Arthur, 2015-02-12
Mudrick @mudrick

You don’t need to scroll the browser - just put .focus() on the element, the browser will scroll where it needs to. (Sorry, didn't notice that the question was asked a year ago :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question