V
V
Valeriy19972015-09-01 22:44:12
JavaScript
Valeriy1997, 2015-09-01 22:44:12

Why is there a selection in the input when the last character is entered?

When you enter the last character in the input, there is a "self-selection", how to remove it?

<input id="phone" type="text" class="form-control" autofocus autocomplete="off" name="phone"  data-mask="+38 (099) 999-99-99" required/>


I tried to style it:

$("#phone").css("-moz-user-select", "-moz-none");
  $("#phone").css("-o-user-select:", "none;");
  $("#phone").css("-khtml-user-select", "none");
  $("#phone").css("-webkit-user-select", "none");
  $("#phone").css("-user-select", "none");


but it doesn't work.

Here is all the code in the sandbox: jsfiddle.net/t52ka/44

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valeriy1997, 2015-09-02
@Valeriy1997

I'm posting the solution to the question, as it is quite possible that someone will have such a problem.
It's all about the Masked Input Plugin. When the position matches the length of the mask, the text is highlighted.
Here is this line:

pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos);

replace it with: writeBuffer(), input.caret(pos);

S
Stalker_RED, 2015-09-01
@Stalker_RED

You have a piece of code there that just abounds with SelectionRange and textRange. It's hard for me to understand why this piece, but it seems that it is he who makes the selection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question