mohsen77sk / angular-touch-keyboard

Virtual Keyboard for Angular applications.
MIT License
49 stars 16 forks source link

respect the maxLength property #11

Closed brynnlow closed 1 year ago

brynnlow commented 1 year ago

it is me again 😆

the virtual keyboard should respect the maxLength property like normal keyboard

brynnlow commented 1 year ago

warning @mohsen77sk in normal situation MaxLength = -1

it can generate bug with const inputMaxLength = this._activeInputElement?.maxLength ?? 0; you have to test is this._activeInputElement?.maxLength > -1

my function

private isMaxLengthReached(output: string): boolean { return this._activeInputElement.maxLength != null && this._activeInputElement.maxLength != -1 && this._activeInputElement.maxLength <= output.length }

if (!this.isStandardButton(button)) { // Handel functional button if (button === fnButton.BACKSPACE) { if (output.length > 0) output = this._removeAt(output, ...commonParams); } else if (button === fnButton.SPACE) { if(!this.isMaxLengthReached(output)) { output = this._addStringAt(output, ' ', ...commonParams); } } else if (button === fnButton.TAB) { if (!this.isMaxLengthReached(output) && this.isTextArea()) { output = this._addStringAt(output, '\t', ...commonParams); } } else if (button === fnButton.ENTER) { if (!this.isMaxLengthReached(output) && this.isTextArea()) { output = this._addStringAt(output, '\n', ...commonParams); } } else { this.layoutName = button.substring(1, button.length - 1); return; } } else { // Handel standard button if (!this.isMaxLengthReached(output)) { output = this._addStringAt(output, button, ...commonParams); } }