-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix custom key with multiple characters #32
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
.gitignore
file changes should be discarded.package-lock.json
file should be removed.yarn.lock
file changes should be discarded.- I've added a suggestion for the fixes that you have committed.
src/kioskboard.js
In addition,
No worries about the distribution, the contribution guideline is not ready yet. So, only the fixes are enough in this case.
Thanks,
Furkan.
package-lock.json
Outdated
@@ -0,0 +1,7849 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file as well. We are using yarn instead of npm.
yarn.lock
Outdated
@@ -2,29 +2,29 @@ | |||
# yarn lockfile v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ignore this file as well.
src/kioskboard.js
Outdated
e.preventDefault(); | ||
|
||
// update the selectionStart | ||
theInputSelIndex = input.selectionStart || (input.value || '').length; | ||
// Math.min prevents out of bound, theInputSelIndex cannot be greater than the length of theInputValArray | ||
theInputSelIndex = Math.min((input.selectionStart || (input.value || '').length),theInputValArray.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes should be discarded if my suggestion on the adding part is ok for you.
src/kioskboard.js
Outdated
theInputValArray.splice(theInputSelIndex, 0, keyValue); | ||
/** Prevents breaking on custom keys that insert multiple characters, for example, imagine a ".com" key, | ||
* it would be inserted into the array as a single element and could no longer be deleted because the length of | ||
* the input would be greater than the length of the array, adding Math.min (and comparing the respective lengths) | ||
* to the backspace key prevents this problem but would delete the entire contents of the key (all characters, for example ".com") | ||
* Instead, concatenate the main array of the contents with a possible array of keyValue, you can delete any single character. | ||
**/ | ||
theInputValArray = theInputValArray.concat(keyValue.split('')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use and update the selection index for adding each character because of the allowRealKeyboard
option.
So, my suggestion is:
- Spliting the
keyValue
for the possibility of the multiple characters. - Creating a
for
loop for the new array of thekeyValue
. - add, update, and dispatch events will be moved in this loop.
keyElm.addEventListener('click', function (e) {
e.preventDefault();
// check input max & maxlength
var maxLength = (input.getAttribute('maxlength') || '') * 1;
var max = (input.getAttribute('max') || '') * 1;
var liveValueLength = (input.value || '').length || 0;
if (maxLength > 0 && liveValueLength >= maxLength) { return false; }
if (max > 0 && liveValueLength >= max) { return false; }
// input trigger focus
input.focus();
// key's value
var keyValue = e.currentTarget.dataset.value || '';
// check capslock
if (isCapsLockActive) {
keyValue = keyValue.toLocaleUpperCase(keyboardLanguage);
} else {
keyValue = keyValue.toLocaleLowerCase(keyboardLanguage);
}
var keyValArr = keyValue.split('');
for (var keyValIndex = 0; keyValIndex < keyValArr.length; keyValIndex++) {
// update the selectionStart
theInputSelIndex = input.selectionStart || (input.value || '').length;
// add value by index
theInputValArray.splice(theInputSelIndex, 0, keyValArr[keyValIndex]);
// update input value
input.value = theInputValArray.join('');
// set next selection index
input.setSelectionRange(theInputSelIndex + 1, theInputSelIndex + 1);
// input trigger change event for update the value
input.dispatchEvent(changeEvent);
}
}, false);
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all ok for me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to replace the keyElm.addEventListener('click', function (e) {...
code block(above) with your current one and update this MR? (with discarding other ones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all changed as you suggested
Hi @skullab , |
fix for issue #31
NOTE:
no distribution version created