angular-virtual-keyboard
angular-virtual-keyboard copied to clipboard
Inputs are being entered from right to left instead of left to right on input fields of type NUMBER
Say for example I want to enter an amount of 1,293 as principal amount but it is accepted as 3,921. Also, the BKSP is not working. I already tried adding css style "direction: ltr" but to no avail. Anyone's help will be much appreciated. Thank you.
I am not 100% sure, but I think it has to do with the support of selectionStart (see https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange, especially browser compatibility note [1]). In Chrome I detected that type email is not supported. Although I am not sure, I suspect Chrome of changing the default setting of selectionStart and selectionEnd into null. Together with the buggy implementation of the following function, the effect will be an inverse of input.
function hasSelectionStartEnd(elem) { var hasSelection = false; try { hasSelection = !isNaN(elem.selectionStart) && !isNaN(elem.selectionEnd); } catch(e) {}; return hasSelection; }
isNaN(null) is false, isNaN(undefined) is true (of course -:)).
Hi, I solve the problem changing this function, just adding one line (194):
function hasSelectionStartEnd(elem) {
//return true;
var hasSelection = false;
try {
hasSelection = !isNaN(elem.selectionStart) && !isNaN(elem.selectionEnd);
} catch (e) {
};
if (elem.type == 'number') hasSelection = false; //change here //line 194
return hasSelection;
}
Hi, after accept number, there another problem with decimals number, then solved with:
line: 907 add:
} else if (this.VKI_target.type =='number') {
if (this.waitingDecimal == undefined)
this.waitingDecimal = false;
if ((text == ',' || text=='.')) {
this.waitingDecimal = true;
} else {
if (this.waitingDecimal) {
this.VKI_target.value += '.'+text;
this.waitingDecimal = false;
} else {
this.VKI_target.value += text;
}
}