NullReference
NullReference

Reputation: 4484

Knockout subscribe update as text is entered into input?

I have an input field that is bound to an observable object. I'm subscribing to the change so I can do some ui changes as they're entering data. Currently the subscribe event gets called after the user clicks outside of the input. Is there any way to change the subscribe so it updates as the user enters characters in the input field?

Upvotes: 0

Views: 216

Answers (2)

Chris Montgomery
Chris Montgomery

Reputation: 2354

Here's how I do it.

HTML:

<input type="text" data-bind="value: filter, valueUpdate: 'afterkeydown'" />

JS:

filter = ko.observable("");

Upvotes: 1

Niko
Niko

Reputation: 26730

There is the "valueUpdate" parameter / "binding" for this:

<input data-bind="value: someObservable, valueUpdate: 'afterkeydown'">

Upvotes: 1

Related Questions