Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout.js hasfocus causes value to be reset when losing focus before the throttle period expires
    text
    copied!<p>Here is a little sample code which illustrates my problem: <a href="http://jsfiddle.net/wsytR/2/" rel="nofollow noreferrer">http://jsfiddle.net/wsytR/2/</a></p> <p>If you change the text in the input and then press tab to blur it the value changes back to the old one. This happens if you switch focus before the <code>throttle</code> period is over. It seems to me the observable isn't getting changed at all in this way.</p> <p>I found <a href="https://stackoverflow.com/questions/12384096/knockout-js-changing-the-hasfocus-value-does-not-update-binding-value">this question</a> and from it got to <a href="https://github.com/SteveSanderson/knockout/issues/321" rel="nofollow noreferrer">this issue</a>. I reordered the bindings so that <code>hasfocus</code> is the first one, but no luck with that.</p> <p>Also if instead of pressing tab to switch focus you press Escape or just click somewhere else on the page, the old value is restored again, but after the throttle period expires the observable gets updated and the value changes yet again, this time to the new one. Probably a different kind of event is triggered by tab and Escape/click.</p> <p>Is there a way to handle this with knockout? Am I trying to do something wrong or something that should not be expected to work in knockout?</p> <h2>Edit:</h2> <p>Turns out I have not formulated my question correctly. I need the focus to be set from my model, so throttling the <code>hasfocus</code> binding does not solve my issue. If you just need to have it update properly after you leave the element but still keeping the throttle, that works great.</p> <p>My goal is to get immediate update upon losing focus, but otherwise throttle the binding while till typing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload