I need a way to check if the cursor is inside a field or not.
elements.fieldname.caretPosition doesn’t really give me the feedback I need:
If my cursor is in the field, at the beginning of the field, elements.fieldname.caretPosition returns a 0.
If my cursor is not in the field, elements.fieldname.caretPosition also returns a 0. (A null would be more useful …
)
What code can I use to check where the cursor is on the form (if anywhere)?
Thanks
Irene
you want the current focused component, We dont have a method that just gives you that
But you can implement this by using the onElementFocusGained/Lost events on a form.
Will onfocus events work if I click on a button next to the text area that I want to fill with content? The cursor is still in the field, but my mouse is now pointing to another element on the form.
Irene
A text field always have a caret position… (but only if focused you see a flashing cursor on the caret position)
If you click on a button then that button gets focus yes. But if you ask for the caret position it still should be on the place where the user “left” it
You seem to want when a button is pressed that the textfield still has focus and there you want to ask the caret position from
This is not possible because the textfield did loose its focus to the button.
So you just have to remember the latest used textfield in this case and ask for the caret position (this is also why a caret position shouldnt return null when not having focus, because for many type of scripts triggered by something else it would be null)