I need to get the caret position for a textarea (which loses focus) when I click on a button.
I tried the getSelectionRange() but I need to have focus for the textArea to use that.
If I use focusInItem on the textArea before getting the selection range it will set the caret to the beginning so getSelectionRange() will always return 0.
There is a simple code that does what I need, but since I do not have access to the textarea element on DOM (probably do not want to have this kind of access anyway) I can' integrate the code.
Demo of the code working in JS: http://demo.vishalon.net/getset.htm
For you adding the code directly to the JS source of your TextAreaItem would be pretty easy.
Can you add this feature or give some ideas to workaround the issue?
P.S: I need focus for the button I am pushing so I can not disable it just to prevent the textArea loosing focus.
Thank you
I tried the getSelectionRange() but I need to have focus for the textArea to use that.
If I use focusInItem on the textArea before getting the selection range it will set the caret to the beginning so getSelectionRange() will always return 0.
There is a simple code that does what I need, but since I do not have access to the textarea element on DOM (probably do not want to have this kind of access anyway) I can' integrate the code.
Code:
function doGetCaretPosition (ctrl) { var CaretPos = 0; // IE Support if (document.selection) { ctrl.focus (); var Sel = document.selection.createRange (); Sel.moveStart ('character', -ctrl.value.length); CaretPos = Sel.text.length; } // Firefox support else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart; return (CaretPos); }
For you adding the code directly to the JS source of your TextAreaItem would be pretty easy.
Can you add this feature or give some ideas to workaround the issue?
P.S: I need focus for the button I am pushing so I can not disable it just to prevent the textArea loosing focus.
Thank you
Comment