Inputmask
Inputmask copied to clipboard
Cursor Position incorrect for programmatic focus
Description:
I'm trying to focus the masked text input with JQuery focus / click events.
However the cursor is either at the end or at the beginning for currency
alias.
Click events didn't work at all.
The Options:
{
alias: 'currency',
groupSeparator: '',
prefix: location_data.currency + ' ',
autoUnmask: true,
allowMinus: false,
positionCaretOnTab: false
}
What I'm trying:
$('#total_override_value').focus();
or
$('#total_override_value').click();
Result:
Expected behavior: It should be the same as when I click the input myself and set the Cursor at the correct position.
Additional Info:
- OS: Windows 10
- Browser: Chrome
- Inputmask version: 5.0.6
Update: It seems to work with the following workaround:
setTimeout(() => {
$('#total_override_value').focus();
setTimeout(function() {
$('#total_override_value').click();
}, 50);
}, 100);
And using this option: positionCaretOnClick: 'radixFocus'
But when clicking manually, I don't need that option.
@AzonInc ,
Set the option positionCaretOnTab: true
$('#total_override_value').focus(); will work then.
Or $("#link").trigger("focus").trigger("click"); with the positionCaretOnTab: false
Hmm strange, here it always seems to work. Can you create a jsfiddle or codepen with an example.
https://jsfiddle.net/BerkerYuceer/cfoyLmkn/ I did not encounter any problem..
@BerkerYuceer ,
When using the latest version.
https://jsfiddle.net/robinherbots/kbg7to0y/4/