mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-01 02:53:07 +08:00
maxLength functionality
This commit is contained in:
parent
282e84941a
commit
d923c5d920
@ -80,9 +80,17 @@ class SimpleKeyboard {
|
||||
if(!this.input[this.options.inputName])
|
||||
this.input[this.options.inputName] = '';
|
||||
|
||||
let updatedInput = Utilities.getUpdatedInput(button, this.input[this.options.inputName], options);
|
||||
let updatedInput = this.utilities.getUpdatedInput(button, this.input[this.options.inputName], this.options, this.caretPosition);
|
||||
|
||||
if(this.input[this.options.inputName] !== updatedInput){
|
||||
|
||||
/**
|
||||
* If maxLength and handleMaxLength yield true, halting
|
||||
*/
|
||||
if(this.options.maxLength && this.utilities.handleMaxLength(this.input, this.options, updatedInput)){
|
||||
return false;
|
||||
}
|
||||
|
||||
this.input[this.options.inputName] = updatedInput;
|
||||
|
||||
if(debug)
|
||||
|
@ -171,7 +171,50 @@ class Utilities {
|
||||
return output;
|
||||
}
|
||||
|
||||
static camelCase = (string) => {
|
||||
handleMaxLength(inputObj, options, updatedInput){
|
||||
let maxLength = options.maxLength;
|
||||
let currentInput = inputObj[options.inputName];
|
||||
let condition = currentInput.length === maxLength;
|
||||
|
||||
|
||||
if(
|
||||
/**
|
||||
* If pressing this button won't add more characters
|
||||
* We exit out of this limiter function
|
||||
*/
|
||||
updatedInput.length <= currentInput.length
|
||||
){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Number.isInteger(maxLength)){
|
||||
if(options.debug){
|
||||
console.log("maxLength (num) reached:", condition);
|
||||
}
|
||||
|
||||
if(condition){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof maxLength === "object"){
|
||||
let condition = currentInput.length === maxLength[options.inputName];
|
||||
|
||||
if(options.debug){
|
||||
console.log("maxLength (obj) reached:", condition);
|
||||
}
|
||||
|
||||
if(condition){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
camelCase = (string) => {
|
||||
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user