Scroll programatically to input with focus


I would like to scroll programmatically to an input that has failed in its validation. The page-content can be quite lengthy

//validate input name
if (!($('#my_input_value').val()))
	//set focus
	//scroll to input
	<! -- Place code here -->
	//alert user
	app.dialog.alert('Please enter a value.');

I can see there is .scrollTop that is used but I can’t quite figure out how to use it.

Any pointers will be appreciated.

var inputVal = $(’#inputVal’);
// alert / toast
app.dialog.alert(‘Your error message’,() =>{
}else if(other_validation){}

scrollTop() Get scrollTop position of element
.scrollTop(position, duration, callback) Set scrollTop “position” with animation during “duration” (in ms). Scroll top position will be set immediately if duration is not specified. If you have specified “callback” function, then it will be executed after scrolling completed

So get the top pos of the element. And then scrolTop to it

Const pos = $$(myEl).scrollTop()


This works well for the input elements that are at the top of the page.

How about those that are centered on the page?

Is there a way to get their position on the page?

There is a app.input.scrollIntoView method

1 Like