Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want it to do updates on <code>afterkeydown</code> "by default," you could inject the <code>valueUpdate</code> binding in the <code>value</code> binding handler. Just supply a new <code>allBindingsAccessor</code> for the handler to use that includes <code>afterkeydown</code>.</p> <pre><code>(function () { var valueHandler = ko.bindingHandlers.value; var getInjectValueUpdate = function (allBindingsAccessor) { var AFTERKEYDOWN = 'afterkeydown'; return function () { var allBindings = ko.utils.extend({}, allBindingsAccessor()), valueUpdate = allBindings.valueUpdate; if (valueUpdate === undefined) { return ko.utils.extend(allBindings, { valueUpdate: AFTERKEYDOWN }); } else if (typeof valueUpdate === 'string' &amp;&amp; valueUpdate !== AFTERKEYDOWN) { return ko.utils.extend(allBindings, { valueUpdate: [valueUpdate, AFTERKEYDOWN] }); } else if (typeof valueUpdate === 'array' &amp;&amp; ko.utils.arrayIndexOf(valueUpdate, AFTERKEYDOWN) === -1) { valueUpdate = ko.utils.arrayPushAll([AFTERKEYDOWN], valueUpdate); return ko.utils.extend(allBindings, {valueUpdate: valueUpdate}); } return allBindings; }; }; ko.bindingHandlers.value = { // only needed for init 'init': function (element, valueAccessor, allBindingsAccessor) { allBindingsAccessor = getInjectValueUpdate(allBindingsAccessor); return valueHandler.init(element, valueAccessor, allBindingsAccessor); }, 'update': valueHandler.update }; } ()); </code></pre> <p>If you're not comfortable "overriding" the <code>value</code> binding, you could give the overriding custom binding a different name and use that binding handler.</p> <pre><code>ko.bindingHandlers.realtimeValue = { 'init':..., 'update':... }; </code></pre> <p><a href="http://jsfiddle.net/LhZB2/1/">demo</a></p> <p>A solution like this would be suitable for Knockout version 2.x. The Knockout team has fleshed out a more complete binding for text-like inputs through the <a href="http://knockoutjs.com/documentation/textinput-binding.html">textInput</a> binding in Knockout version 3 and up. It was designed to handle all text input methods for text inputs and <code>textarea</code>. It will even handle real time updating which effectively renders this approach obsolete.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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