webOS Nation Forums
> webOS apps and software
> webOS development
>
Moving cursor in textfield
I figured this has been covered so I looked really hard but cannot find the answer.
I want to allow the user to move the cursor in the textfield, then by selection, insert text into this textfield. Changing the textfield works but I need to find out where the cursor is located. How do I do this?
The next problem is, I can't seem to move the cursor after the insert is done.
If the focus is taken off the textfield, using the mojo.focus() puts the cursor at the end of the text if the focusMode set to "Mojo.Widget.focusAppendMode". However, if the focus remains on the textfield when the text is changed, the text gets added but the cursor remains in the same spot.
I know there's a trick here but I can't figure it out. Help?
Is not a user allowed to move the cursor by pressing Orng or Shift key and using the gesture area to move it left and right?
Originally Posted by konstantin.neo:
Is not a user allowed to move the cursor by pressing Orng or Shift key and using the gesture area to move it left and right?
The user can move the cursor but the app needs to know where the cursor is located so that the text can be inserted in the correct place. After the insertion, the cursor has to be moved to after the inserted text.
So far, I cannot find any API to do this. In case you're wondering, I've tried the normal
JS code:
[CODE]var txtarea = document.getElementById("message");
var strPos = txtarea.selectionStart;[/CODE]
But this does not work because the textfields are not normal HTML forms.
Help!
Member:
xschemer
at: 07:23 PM 02/11/2010
The framework CSS suggests that there somewhere *is* an input element, so perhaps you could try to access that one directly by using getElementsByTagName?
[CODE]
var inputs = this.controller.get("message").getElementsByTagName("input");
if (inputs && inputs.length > 0) {
this.textInputElement = inputs[0];
}
[/CODE]
Dunno if this works though...
Member:
abegee
at: 11:07 PM 02/11/2010
[code]var cursorPosition = $('textField').mojo.getCursorPosition();
var cursorPosition = cursorPosition.selectionStart
$("textField").mojo.setCursorPosition(cursorPosition, cursorPosition)
[code]
Method Arguments Description
---------------------------------------------------------------------------------------------------------------------------------
focus none Focus the input part of the text field
blur none Blur the input part of the text field
getValue none Get the plaintext value of the text field
setText String DEPRECATED Set the plaintext value of the text field; also used by alt char picker to set the value
setValue String Set the plaintext value of the text field
getCursorPosition none Returns on object with {selectionStart: int, selectionEnd: int} that describe the position of the cursor; if start is not
equal to end, then there is text selected
setCursorPosition start, end Set the cursor position in the input portion of the textfield; if start and end are not the same, then this
will select the text between START and END; if start and/ or end occur in invalid positions, they will be changed
to valid positions at the end of the text if they were larger than the size of the value, or at the beginning, if they
are smaller than the size of the value; empty text will result in a cursor at the start of the textfield
webOS Nation Forums
> webOS apps and software
> webOS development
>
Moving cursor in textfield