I am always glad to see that the "newbie" decided to switch to KnockoutJS. Anything that can help save the world from detailed, custom solutions related to data binding is a wonderful thing.
To answer the question of how to disable multiple events in order to update the data binding value, you should write:
<input data-bind="value:someObservable, valueUpdate: ['blur', 'afterKeyDown', 'onLoad']"/>
In my case, I used bootstrap typeahead to select a value, but the data binding was not updated after the user made a selection from the drop-down help box. Looking at the source, I found this little hidden stone that was not mentioned in KO documents.
I am compressing a message to someone, βgo read the source,β but if you are dealing with a brief case that is not covered in the documents, don't be afraid! I discovered many undocumented functions by doing this
source: https://github.com/knockout/knockout/blob/master/src/binding/defaultBindings/value.js
ko.bindingHandlers['value'] = { 'init': function (element, valueAccessor, allBindingsAccessor) { // Always catch "change" event; possibly other events too if asked var eventsToCatch = ["change"]; var requestedEventsToCatch = allBindingsAccessor()["valueUpdate"]; var propertyChangedFired = false; if (requestedEventsToCatch) { // Allow both individual event names, and arrays of event names if (typeof requestedEventsToCatch == "string") requestedEventsToCatch = [requestedEventsToCatch]; ko.utils.arrayPushAll(eventsToCatch, requestedEventsToCatch); eventsToCatch = ko.utils.arrayGetDistinctValues(eventsToCatch); } .... truncated ....
Depending on your familiarity with record bindings, it may be pretty obvious that the valueUpdate binding handles an array of events. Here they get the extra valueUpdate binding and store it in var requestedEventsToCatch . The following comment notes the logic of processing an array of events to update a value - in fact, they even use one event, such as "afterKeyDown" to ["afterKeyDown"]
Hope this helps!
matrix10657
source share