Page 1 of 1

prefilled text in a textarea

Posted: Wed Sep 14, 2022 4:33 pm
by mperez
The record format contains a textarea and a button in a css panel. Prior to exfmt, the textarea field is pre-filled with some text by the RPG program. When it displays on the screen, the textarea has focus and its text is selected. I'm not sure how to unselect the text so the cursor is positioned after the pre-filled text. The intent is for the user to enter additional comments after the pre-filled text.

I tried adding the following js in the textarea onfocus() event, but the text remained selected.

input = this;
if (input.setSelectionRange) {
window.getSelection().removeAllRanges();
}

Re: prefilled text in a textarea

Posted: Thu Sep 15, 2022 4:35 pm
by mperez
One workaround I found is to set the "no focus" property on the format. The user will need to click on the textarea, but the cursor will be positioned at the end of the prefilled text.

Re: prefilled text in a textarea

Posted: Wed Sep 21, 2022 9:03 am
by CAPL_INFO
You can get the HTML DOM element corresponding to the textArea and then set the selectionStart.
The DOM element should have the same ID as the PUI widget.
So basically

Code: Select all

var txtarea = document.getElementById("the_text_area_id_here");
txtarea.selectionStart = txtarea.selectionEnd;