When you enter the last character into the inut (from the virtual keyboard), all text is highlighted in blue. I think that rather the problem is in this piece of code, which is needed, for the collaboration of the field mask and the Wirth keyboard. But where there is a mistake I do not understand.

But I noticed that if you click into a non-input and when typing from a normal keyboard, the text is not highlighted (most likely due to a loss of focus). So the event blur, I tried to hang at the moment when the last character is entered in the input, but this did not help. Tell me, what can I do?

jQuery.fn.extend({ insertAtCaret: function(myValue) { return this.each(function(i) { if (document.selection) { //For browsers like Internet Explorer this.focus(); var sel = document.selection.createRange(); // console.log(sel) sel.text = myValue; console.log(sel.text) this.focus(); } else if (this.selectionStart || this.selectionStart == '0') { //For browsers like Firefox and Webkit based var startPos = this.selectionStart; console.log(this.selectionStart) var endPos = this.selectionEnd; var scrollTop = this.scrollTop; // console.log(scrollTop) this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length); this.focus(); this.selectionStart = startPos + myValue.length; this.selectionEnd = startPos + myValue.length; this.scrollTop = scrollTop; } else { this.value += myValue; this.focus(); } }); } }); 

Here is the full code: http://jsfiddle.net/t52ka/44/

  • 3
    1. Congratulations, you were able to emulate events) 2. Before uploading the JS code, it is useful to bring it into a normal form, I use this jsbeautifier.org 3. Selection of the whole imput also happens if you remove the focus-select to focus when all the numbers are filled with a virtual keyboard or with a normal one. Apparently something happens with this. - Vartlok

1 answer 1

In general, problems with the selection in the function on("focus.mask", function() {

To avoid the selection:

 .on("focus.mask", function() { if (!input.prop("readonly")) { clearTimeout(caretTimeoutId); var pos; focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() { writeBuffer(), input.caret(pos); // ИСПРАВЛЕНО ТУТ }, 10); } }) 

In the old code it was:

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

Those. when the position coincided with the long mask (in your case 19) the whole line was selected.