As I work with angular template-driven forms, a peculiar issue arises when handling the dot character input by users. Rather than allowing it to be added normally to the input field, my goal is to capture the event and switch focus to a different text input.
To achieve this functionality, I am utilizing (keyup.dot)
to detect the event and have implemented a method to handle it.
<input [(ngModel)]="word" name="word" (keyup.dot)="focusOtherInput($event)">
Despite employing e.preventDefault()
within the method to prevent the dot from being included in the input field, it seems that the character is still appearing. (Fortunately, the focus transition to the other input works seamlessly.)
focusOtherInput(e: KeyboardEvent) {
e.preventDefault();
// Additional code for focusing on the alternate input
}
The perplexing question that emerges is why e.preventDefault()
fails to function in this particular context?