SB2055
SB2055

Reputation: 12862

Binding an event to the "tab" button via knockout?

I'd like to call a method if the user "tabs" out of a field. It shouldn't be called when focus is lost or when the user clicks elsewhere - only if they tab out of the field. Does knockout make this especially easy by any chance, or should I start digging into some kind of jQuery solution?

Upvotes: 1

Views: 2282

Answers (1)

Kyeotic
Kyeotic

Reputation: 19847

You can use the event binding to do this, here is a fiddle

<input data-bind="event: { keydown: tabOut}" />


var ViewModel = function() {
    this.tabOut = function(data, event) {
        if (event.keyCode == 9) {
            console.log("tab was pressed");
        };
        return true;
    };
};

Upvotes: 2

Related Questions