Reputation: 1164
My question is why my two data-bound input fields are behaving differently when I clear them, even though as far as I can tell they are set up the same way as calculated observables in knockout.
Using this fiddle: http://jsfiddle.net/ya7eF/167/
The 'min' field is working properly, the 'hrs' field is not. To reproduce my problem, follow the steps below. When I remove text from Duration 'hrs' field, I want to understand why it is not replaced with zero on blur, like the min field.
Upvotes: 0
Views: 1143
Reputation: 114792
In the second case the value of the Duration
observable did not actually change. When an observable's value is set to its current value, then no notifications are sent out to subscribers. This means that the read functions of your computed observables are not triggered.
One technique to deal with this concern is to use an observable's valueHasMutated
function to ensure that notifications are sent out. To avoid multiple notifications, you could do something like:
if (totalMinutes !== self.Duration()) {
self.Duration(totalMinutes);
}
self.Duration.valueHasMutated();
Here is your sample updated: http://jsfiddle.net/rniemeyer/ya7eF/168/
Upvotes: 1