Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: "tab" keycode event not firing

I have a form field with a handler that I want to trigger after the user deliberately accepts the value with either return/enter or tabs to the next field. I can't use onBlur in this case, since it of course triggers if the user or system blur the field. I only want it on a keyup.

So I have this. I had the enter first, and it works great. But the keycode==9 does not trigger the handler. The focus merely moves to the next field.

ng-keyup="($event.keyCode == 13 || 
           $event.keyCode == 9) 
           && packages.submitNumber('add', packages.addTrackingNumber)"

Is there a way to have this fire on enter OR tab?

like image 839
Steve Avatar asked Jul 21 '15 12:07

Steve


1 Answers

Tab button in html is tabulating to the next focusable element (buttons, inputs etc.). So when you keydown tab button keyup is happening on the next focusable. To avoid this you can try to use ng-keydown. See working example

like image 88
Andrey Avatar answered Nov 19 '22 02:11

Andrey