Skip to content

Commit

Permalink
Reference issue furcan#19
Browse files Browse the repository at this point in the history
- Bug fixed wrong input variable
- Patch to kioskboard-aio.js
  • Loading branch information
dhinugraha committed Mar 29, 2021
1 parent cea8d95 commit 8f3b3b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
24 changes: 24 additions & 0 deletions src/all-in-one/kioskboard-aio.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,17 @@
keyElm.addEventListener('click', function (e) {
e.preventDefault();

// start patch for caret position, add value at current carret position
var startPos = input.selectionStart;
// prevent carret to the end of text if caret position = 0
if(startPos === 0) {
var theInputSelIndex = 0;
} else {
var theInputSelIndex = startPos;
input.setSelectionRange(startPos, startPos);
}
// end patch for caret position

// input trigger change for selectionStart
input.dispatchEvent(changeEvent);

Expand All @@ -575,6 +586,10 @@
// update input value
input.value = theInputValArray.join('');

// start patch for caret position, move carret position after type
input.setSelectionRange(startPos+1, startPos+1);
// end patch for caret position

}, false);
}
}
Expand Down Expand Up @@ -607,6 +622,11 @@
var backspaceKeyElm = window.document.getElementById(kioskBoardVirtualKeyboard.id).getElementsByClassName('kioskboard-key-backspace')[0];
if (backspaceKeyElm) {
backspaceKeyElm.addEventListener('click', function (e) {
// start patch for caret position for backspace
var startPos = input.selectionStart;
input.setSelectionRange(startPos, startPos);
// end patch for caret position

e.preventDefault();

// trigger for selectionStart
Expand All @@ -621,6 +641,10 @@
// update input value
input.value = theInputValArray.join('');

// start patch for caret position for backspace
input.setSelectionRange(startPos-1, startPos - 1);
// end patch for caret position for backspace

}, false);
}
// backspace key click listener: end
Expand Down
22 changes: 10 additions & 12 deletions src/kioskboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,14 @@
var keyElm = eachKeyElm[i];
keyElm.addEventListener('click', function (e) {
// start patch for caret position, add value at current carret position
var startPos = b.selectionStart;

var startPos = input.selectionStart;
// prevent carret to the end of text if caret position = 0
if(startPos === 0) {
var theInputSelIndex = 0;
} else {
theInputSelIndex = startPos;
input.setSelectionRange(startPos, startPos);
}
if(startPos === 0) {
var theInputSelIndex = 0;
} else {
var theInputSelIndex = startPos;
input.setSelectionRange(startPos, startPos);
}
// end patch for caret position

e.preventDefault();
Expand Down Expand Up @@ -587,8 +586,7 @@
input.value = theInputValArray.join('');

// start patch for caret position, move carret position after type
b.setSelectionRange(startPos+1, startPos+1);
var endPos = b.selectionStart;
input.setSelectionRange(startPos+1, startPos+1);
// end patch for caret position

}, false);
Expand Down Expand Up @@ -627,7 +625,7 @@

// start patch for caret position for backspace
var startPos = input.selectionStart;
b.setSelectionRange(startPos, startPos);
input.setSelectionRange(startPos, startPos);
// end patch for caret position

e.preventDefault();
Expand All @@ -645,7 +643,7 @@
input.value = theInputValArray.join('');

// start patch for caret position for backspace
b.setSelectionRange(startPos-1, startPos - 1);
input.setSelectionRange(startPos-1, startPos - 1);
// end patch for caret position for backspace

}, false);
Expand Down

0 comments on commit 8f3b3b6

Please sign in to comment.