Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  101] [ 6]  / answers: 1 / hits: 21104  / 6 Years ago, fri, october 5, 2018, 12:00:00

I have used (keydown) event in angular 6 to bind key inputs



So on enter of 'Tab' and 'Enter' key i have to do my functionality
and added a event.prevent default



But when Shift + Tab is entered it is also preventing the event



.html



<input type=text [(ngModel)]=Result1 (keydown)=onKeydownMain($event)  >


I dont want (keydown.shift.tab) event seperate..



.ts



public onKeydownMain(event): void {
if (event.key === Enter || event.key === Tab) {
event.preventDefault();
// My Functionality goes here
}
}



But the problem is when Shift + Tab is pressed , event is fired and functionality goes on, which i don't want.




How can i go this



I just want Shift + Tab to perform its default functionality on this input.


More From » html

 Answers
31

You need to remove the shift in the if condition like this:



public onKeydownMain(event): void {
if (!event.shiftKey && (event.key === Enter || event.key === Tab)){
event.preventDefault();
// My Functionality goes here
}
}


You can refer to https://www.w3schools.com/jsref/obj_keyboardevent.asp for KeyboardEvent


[#53369] Monday, October 1, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ulysses

Total Points: 111
Total Questions: 118
Total Answers: 113

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;