How can I use a jQuery UI Spinner widget in Knockout bound input?
<tbody data-bind="foreach: orders">
<tr>
<td data-bind="text: Name"></td>
<td><input type="number" style="width: 100px;" data-bind="value: Price" /></td>
<td><input type="number" style="width: 50px;" data-bind="value: VAT" /></td>
<td><input type="number" style="width: 50px;" data-bind="value: Number" /></td>
<td data-bind="text: Final()"></td>
<td><a href="javascript:void(0);" data-bind="click: $root.removeOrder">Remove</a></td>
</tr>
</tbody>
@Artem Vyshniakov's answer is right on. However, if you're looking for an IE polyfill instead of replacing the html5 number input in browsers that support it, try this:
Complete Fiddle here: http://jsfiddle.net/mberkom/pCJWc/
The best way is to create
custom binding
to bindspinner
to the input:And then just use it instead of
value
binding:Here is working fiddle: http://jsfiddle.net/vyshniakov/SwKGb/
The answers on this page are correct and helpful. I found, however, that I was getting bad behaviour when someone was typing a value in the field. Each key press seems to fire a "spinstop" event too. Further, the keypresses were bypassing the field formatting and options.step. Fortunately we can examine the incoming event to see what's actually happening. There may be better ways but I thought I'd share anyway.