Frage

Hi! I was wondering how to use the tab button on the keyboard to call a function? Something like this:

<button 
    class="btn btn-primary order-input-add" 
    ui-keypress="{13:'add_plu(order.orderwindow.add_field)'}" 
    ng-click="add_plu(order.orderwindow.add_field)">Add
</button>

This code segment allows me to press "enter" to call function "add_plu()". This uses angular ui utility library.

Thanks

War es hilfreich?

Lösung

The keypress event is fired when a key is pressed down and that key normally produces a character value.

You can use the keydown event instead:

ui-keydown="{ 'tab':'add_plu(order.orderwindow.add_field)'}"

Demo: http://plnkr.co/edit/XMRlVLnw2BEyoVgvQyW9?p=preview

Note that you need to click the button first to give it focus, which is another issue.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top