I have that a custom binding that fires for each element on the page that uses the same binding ie. this code will fire the binding 3 times when I enter text in the first field.
<input data-bind="pinTest: propertyOne" />
<input data-bind="pinTest: propertyTwo" />
<input data-bind="pinTest: propertyThree" />
How do I get it to only fire once? I've tried knockout v2.3 and v3.
I've got a working example of the issue at http://jsbin.com/UKewOvu/2/edit?html,js,console,output
Here's the code:
ko.bindingHandlers.pinTest = {
init: function (element, valueAccessor, allBindingsAccessor) {
ko.utils.registerEventHandler(element, "keyup", function () {
var value = valueAccessor();
value(element.value);
});
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var value = ko.unwrap(bindingContext.$data.propertyOne);
console.log("in binding update -value="+value);
}
};
var myVm = function () {
this.propertyOne = ko.observable();
this.propertyTwo = ko.observable();
this.propertyThree = ko.observable();
};
function start() {
ko.applyBindings(new myVm());
}