Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

valueUpdate: 'afterkeydown' for input type="numeric" in Knockoutjs 2.0

[see fiddle for illustration]

I set up a value bind to an input of type number, and want the bound observable to immediately reflect changes to the value of the field. to do that I set the afterkeydown valueUpdate binding. This works well for changing the number input using the arrow up and arrow down keys. However, if I change the number using the browser-generated (tested in chrome) increment/decrement control the change is only reflected upon changing focus to a different element. I assume this reflects the default update upon change event.

My question is whether there is any way to set the update to occur for both changes using the up down keyboard errors and browser-generated up/down error controls?

like image 672
odedbd Avatar asked Apr 15 '12 19:04

odedbd


1 Answers

The valueUpdate additional binding can take an array of events. It looks like the oninput event is fired when clicking on the up/down arrows.

So, you can bind it like:

<input type="number" data-bind="value: y, valueUpdate: ['afterkeydown', 'input']"/>

http://jsfiddle.net/rniemeyer/hY5T2/9/

like image 106
RP Niemeyer Avatar answered Nov 10 '22 23:11

RP Niemeyer