maxLength functionality

This commit is contained in:
Francisco Hodge 2018-10-06 02:18:55 -04:00
parent 282e84941a
commit d923c5d920
2 changed files with 53 additions and 2 deletions

View File

@ -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)

View File

@ -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));
};