Created
December 12, 2018 18:35
-
-
Save xantiagoma/c9b735f0261d585d87f219b74b238686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onEdit($event: Event) { | |
if( $event instanceof KeyboardEvent ) { | |
let key = ($event.keyCode || $event.charCode); | |
let maxLength = ($event.target as HTMLInputElement).maxLength; | |
let valueLength = ($event.target as HTMLInputElement).value.length; | |
if(maxLength === valueLength) { | |
let index = this.inputs.map(e => e.nativeElement) | |
.findIndex(e => e === $event.target); | |
let next = (index + 1) > (this.inputs.length - 1) ? (this.inputs.length - 1) : (index + 1); | |
(this.inputs[next].nativeElement as HTMLInputElement).focus(); | |
} | |
if( (key == 8 || key == 46) && valueLength == 0 ){ | |
let index = this.inputs.map(e => e.nativeElement) | |
.findIndex(e => e === $event.target); | |
let prev = (index - 1) == -1 ? 0 : (index - 1); | |
(this.inputs[prev].nativeElement as HTMLInputElement).focus(); | |
} | |
} else if ( $event instanceof FocusEvent ) { | |
} | |
//var value = this.editor.nativeElement.textContent; | |
this.update.emit(this.val); | |
} | |
// (keyup)="onEdit($event)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment