Page 1 of 1

Cursor position at top of textArea

Posted: Mon Jun 25, 2018 1:17 pm
by mjavier
Is there a way to position the cursor at the top of the textArea. I've searched google but could not find any Profound specific textArea widget.

Re: Cursor position at top of textArea

Posted: Mon Jun 25, 2018 1:56 pm
by Scott Klement
Isn't that where it positions to when you tab to the text area?

Under what circumstances do you want it to behave differently?

Re: Cursor position at top of textArea

Posted: Mon Jun 25, 2018 2:00 pm
by mjavier
When the textArea contains about 2000 characters. The cursor would position to the bottom, or at the end of the textArea. What we wanted to do is to be consistent with the green screen "subfile" where the first record is positioned at the top along with the cursor.

Re: Cursor position at top of textArea

Posted: Mon Jun 25, 2018 2:01 pm
by Megan
Hello Mario,

It is possible to position the cursor at the top. This would be accomplished with JavaScript added to an event of the widget. For your situation, you may want to use the onfocus or onclick events. Here is some example code:

Code: Select all

input = this; // 'This' refers to the element that had its event triggered.
input.scrollTop = 0; // Scroll to the the top of the widget.
if (input.setSelectionRange) {
  input.focus();
  input.setSelectionRange(0, 0);
}
else if (input.createTextRange) {
  var range = input.createTextRange();
  range.collapse(true);
  range.moveEnd('character', 0);
  range.moveStart('character', 0);
  range.select();
}
When this code is added to the onfocus event, it will scroll to the top of the widget and position the cursor at the start when focused in some way other than clicking directly in the widget (so by tab or by clicking non-text areas of the widget). Click the text area of the widget will position the cursor at the click-point.

When this code is added to the onclick event, it will scroll to the top of the widget and position the cursor at the start any time the widget is clicked. This means that the cursor can only be moved with the arrow keys inside the textarea, clicking will always reset it to the start (0) position.

We hope this helps!

Thanks,

Re: Cursor position at top of textArea

Posted: Mon Jun 25, 2018 2:46 pm
by mjavier
Thank you Megan. This works.