I'm using knockoutjs with protected observable and am having an issue with checkboxes. One implementation of protected observables can be found here but there are several that I've seen that are very similar.
A jsFiddle that demonstrates my issue can be found here. Here is a portion of the fiddle.
var ViewModel = function() {
var self = this;
self.protectedBool = ko.protectedObservable(true);
self.commit = function(){
ko.commitProtectedObservables(self);
};
self.rollback = function() {
ko.rollbackProtectedObservables(self);
};
};
$(function() {
ko.applyBindings(new ViewModel());
});
To duplicate, do the following:
The "write" event in the computed observable inside the protectedObservable definition does not get fired the second time you change the checkbox and thus when the value is commited, it's committing the incorrect value.
Also note that the protectedObservable works perfectly for strings. Any guidance would be greatly appreciated.
protectedObservable
's implementation is very old. It works with older versions of KO (<2) only.
For new KO versions refer the editor pattern implemented by the same author (Ryan Niemeyer) - http://www.knockmeout.net/2013/01/simple-editor-pattern-knockout-js.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With