Consider the following trivial example:
<input data-bind="value: query, valueUpdate: 'afterkeydown'"/>
In knockoutjs 2.1.0, when I press any of ctrl,Up arrow,Down arrow,Shift the binding is not fired and query is not updated.
In knockoutjs 2.2.0, the binding fires for all the above keypresses.
This is playing havoc with some existing code (it’s an autocomplete, and arrow up and down are frequently used to select from the drop down).
Which behaviour is correct? I assume technically, the latter is correct as these pressing these keys is a keydown event, but shouldn’t the binding only fire if the value has changed?
I want to keep everything real-time, and the docs state:
“afterkeydown” is the best choice if you want to keep your view model updated in real-time
Suggestions?
- ko 2.1.0 demo: http://jsfiddle.net/Rmcza/7/
- ko 2.2.0 demo: http://jsfiddle.net/Rmcza/8/
I think this is a result of this change made by RP Niemeyer in Sept. It causes computed observables to always write when triggered, even if the value hasn’t changed.
You will notice in this fiddle that this does not occur when using a non-computed observable. I tested this using an explicit subscription, and the event does not fire for the down arrow.
Maybe Ryan can explain why this was changed, and why computed’s are behaving differently than regular observables in this case. You might want to make an issue on the GitHub page.