Does anyone know if there is a way to get the position of the caret in a textBox?
E.g. something like, but something that works
export function textBox2_keyPress(event) {
let position = event.key;
const getCaretPosition = position.selectionStart;
console.log(getCaretPosition);
}
or the equivalent of
export function textBox2_keyPress(event) {
var ctl = document.getElementById('Javascript_example');
var startPos = ctl.selectionStart;
var endPos = ctl.selectionEnd;
alert(startPos + ", " + endPos);
}
Option 2 (more complicated, but you get it with each key type):
Add a custom element to your page.
In the custom element file add an onKeyDown event listener to the window.
Once clicked get the event.target coordinates and move them to the Velo page code (with dispatchEvent). An in the Velo onKeyPress handler, read the latest received values (set a small timeout for that)
Ah, so you meant position in character index. Sorry I read your original post too quickly.
I think the only way to do it is by setting an event listener in a custom element and dispatch the event.target.selectionStart.