Inputmask icon indicating copy to clipboard operation
Inputmask copied to clipboard

Cursor Position incorrect for programmatic focus

Open AzonInc opened this issue 2 years ago • 6 comments

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: image image

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

AzonInc avatar Dec 18 '21 02:12 AzonInc

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 avatar Dec 18 '21 02:12 AzonInc

@AzonInc ,

Set the option positionCaretOnTab: true

$('#total_override_value').focus(); will work then.

RobinHerbots avatar Jan 28 '22 09:01 RobinHerbots

Or $("#link").trigger("focus").trigger("click"); with the positionCaretOnTab: false

RobinHerbots avatar Jan 28 '22 09:01 RobinHerbots

Hmm strange, here it always seems to work. Can you create a jsfiddle or codepen with an example.

RobinHerbots avatar Jan 28 '22 09:01 RobinHerbots

https://jsfiddle.net/BerkerYuceer/cfoyLmkn/ I did not encounter any problem..

BerkerYuceer avatar Mar 15 '22 08:03 BerkerYuceer

@BerkerYuceer ,

When using the latest version.

https://jsfiddle.net/robinherbots/kbg7to0y/4/

RobinHerbots avatar Apr 08 '22 09:04 RobinHerbots