I have a checkbox bound to an observable on a view model. I have a requirement to essentially pop up an “Are you sure?” confirmation prompt if the user changes it from true to false. I’m having a horrible time figuring out the best place to make the change “cancelable” . . .
1) jQuery handler for click event
2) Viewmodel internal subscribe “beforeChange”
3) Viewmodel internal subscribe (normal)
In any case, I’d vastly prefer to have the chance to cancel the change outright than react to the change, potentially reverting it back to its previous value if need be.
Does Knockout’s subscribe event give you the chance to cancel a change? Any insight would be appreciated. Thanks!
Here is a simple option using jQuery’s stopImmediatePropagation:
http://jsfiddle.net/rniemeyer/cBvXM/
js: