Knockout checkbox change event sends old value

Since you persisted on stating that the lack of ko.observables is not an issue, I’ve looked at it closer. It seems, that you are correct! The change event is fired before the actual value is set. I’m afraid I do not know the reason for this.

But there is an easy way to fix this: just change change event to click event:

<input type="checkbox" data-bind="checked: ShowOpened, click: $root.CategoryChange" />

Remember, that you have to explicitly put return true; at the end of click event handler. Otherwise the new value won’t be set to checkbox.

If you do not want to use click event, then you can do it the other way. Subscribe to changes of ShowOpened:

this.ShowOpened = ko.observable(ShowOpened);
this.ShowOpened.subscribe(function(newValue) {
    /* Do something when ShowOpened changes.
       newValue variable holds the new value, obviously. :) */
});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)