Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputTextarea autoscroll behavior

I have a inputTextarea that I refresh using PrimeFaces' AJAX poll.

When the inputTextarea is refreshed, a lot of new text will be displayed. However, it will always jump to the first line after refresh. If the user wants to scroll down and the poll/refresh happens, it will jump to the top anyway.

Is there anything I can do to prevent the jumping to the top (or better: prevent jumping at all)? If not, can I make the inputTextarea stay on the bottom at least? (Since the new lines will be appended to the bottom.)

I'm using JSF 2 (MyFaces), Tomahawk and PrimeFaces.

like image 401
geeehhdaa Avatar asked Dec 27 '25 21:12

geeehhdaa


1 Answers

Use JavaScript. Include this script below the <h:inputTextarea> in the portion which is been updated by <p:poll> or in a function when the component supports oncomplete (not sure as I don't have recent PF documentation).

var textarea = document.getElementById("clientIdOfTheTextarea");
textarea.scrollTop = textarea.scrollHeight; // Scrolls to bottom.
like image 174
BalusC Avatar answered Dec 30 '25 10:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!