Im using a FeedbackPanel to show errormessage during validation controlls in a wicket form. When the message occurs it occur in the top of the form(page). And my problem is that I might scrolled down when making a input and than I cant see the errormessage if I dont croll the form to the top of the page. I would like to know how I can set the focus on the feedbackpanel so that everytime a errormessage is shown the form scrolls to the top automatically.
I assume you use ajax-submit?
Then you can add a javascript / jQuery to the AjaxRequestTarget
. For example this:
String myScript = " $('html, body').animate({scrollTop:$('#ELEMENT_ID').offset().top - 20}, 'slow');";
ajaxRequestTarget.appendJavascript(myScript);
Where you need to set the #ELEMENT_ID
to your form.
Or alternatively, if you set a HTML
ANCHOR
(#)
function scrollTo(hash) {
location.hash = "#" + hash;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.