0

What I am trying to achieve is to intercept a keypress event and make the app behave as if another key was pressed, e.g. if a user presses a comma key when in an input element, I want this to be replaced with the dot key being pressed, or another example if a user presses enter, I want it to react as if the tab key was pressed.

zszep
  • 4,450
  • 4
  • 38
  • 58

1 Answers1

1

It sounds like you are having user to fill in a form.

I do not agree on 'replacing' pressed key. I think it will lead to chaos, plus, no matter how you do it (using JQuery.trigger or jQuery plugin like sendkey), you will have to wrap it into directive anyway (for notifying angular external events/changes).

However, you can register an ng-change event to the input and replace all commas with dots.

For moving the focus, you can register a keyup event by using a directive llike this and move the focus to the next sibling field or any input you wish.

Community
  • 1
  • 1
David Lin
  • 13,168
  • 5
  • 46
  • 46
  • note that you would have to handle situation like.: user moves the carret to the begining of the input and starts typing. copy paste (in the middle of the string) etc – marcinn Jun 24 '14 at 09:34
  • You're probably right. Eventually how I did it was by listening to the keydown event and then doing a replace "comma" with "dot" on the input value. – zszep Jun 24 '14 at 17:35