I'm developing web application which depends heavily on knockouts.js
In one "screen" i'm using jquery ui dialog box to add some data.
when the user hits add button popup dialog box is shown with 1 text
box. this text box is binded to some property in my view model.
When the user starts typing text into that text box and after that
hits close button on the dialog, view model is not updated because the
blur event did not fire on the text box.
Second time when dialog box is shown to the user the previous text
entered is still there.
I tried to update the view model in before dialog is shown but the
text is still there.
After some investigation in knockout.js i found this
function observable() {
if (arguments.length > 0) {
// Write
if ((!observable['equalityComparer']) || !
observable['equalityComparer'](_latestValue, arguments[0])) {
observable.valueWillMutate();
_latestValue = arguments[0];
observable.valueHasMutated();
}
return this; // Permits chained assignments
}
else {
// Read
ko.dependencyDetection.registerDependency(observable); //
The caller only needs to be notified of changes if they did a "read"
operation
return _latestValue;
}
}
which means that the value of observable is not updated with empty
value because _latestValue is empty.
so i changed function observable with this
function observable(newValue,forceWrite) {
if (arguments.length > 0) {
// Write
if(forceWrite){
observable.valueWillMutate();
_latestValue = arguments[0];
observable.valueHasMutated();
}
else{
// Ignore writes if the value hasn't changed
if ((!observable['equalityComparer']) || !
observable['equalityComparer'](_latestValue, arguments[0])) {
observable.valueWillMutate();
_latestValue = arguments[0];
observable.valueHasMutated();
}
}
return this; // Permits chained assignments
}
else {
// Read
ko.dependencyDetection.registerDependency(observable); //
The caller only needs to be notified of changes if they did a "read"
operation
return _latestValue;
}
}
in this way i can force value change even the _latestValue and new
value are same.
Is there any other way to force value update (without modificationn of
knockout.js ) ?
-- Michael