02/09/2010, 09:45 AM
|
#1 (permalink) |
|
Member
![]() Join Date: Aug 2009
Location: Los Angeles
Posts: 159
Likes Received: 0
Thanks: 21
Thanked 11 Times in 11 Posts
|
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?
__________________
mobigamedepot.com |
02/11/2010, 04:35 PM
|
#3 (permalink) | |
|
Member
![]() Join Date: Aug 2009
Location: Los Angeles
Posts: 159
Likes Received: 0
Thanks: 21
Thanked 11 Times in 11 Posts
|
Quote:
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;
Help!
__________________
mobigamedepot.com |
|
02/11/2010, 06:23 PM
|
#4 (permalink) |
|
Member
![]() ![]() Join Date: Jan 2010
Location: Munich, Germany
Posts: 33
Likes Received: 0
Thanks: 4
Thanked 65 Times in 9 Posts
|
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];
}
|
02/11/2010, 10:07 PM
|
#5 (permalink) |
|
Member
![]() ![]() Join Date: Aug 2009
Posts: 830
Likes Received: 3
Thanks: 19
Thanked 249 Times in 131 Posts
|
[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 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|



