I've built a very data/number heavy app in Knockout. I'm currently getting the error:
Uncaught Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.
This is happening when my custom bindingHandler (which formats the numbers into 'large' form, ie. 123,345,678,987) tries to write back to the original input which displays the value of a computed function.
Value displayed in an input element:
self.value = ko.computed(function(){
return self.chosenAge().population; // 'fetched' from an array.
});
Binding Handler:
ko.bindingHandlers.largeNumber = {
init: function(element, valueAccessor) {
numberInit(element);
var value = valueAccessor();
var interceptor = ko.computed({
read: function() {
// inject number formatting
return numeral(ko.unwrap(value)).format('0,0');
},
write: function(newValue) {
// remove formatting when writing a new value
value(numeral().unformat(newValue));
}
});
// display new value in target element
if(element.tagName.toLowerCase() == 'input' ) {
ko.applyBindingsToNode(element, {
value: interceptor
});
}
else {
ko.applyBindingsToNode(element, {
text: interceptor
});
}
}
};
valuecomputed? Or you want to update thepopulation? - nemesvlargeNumberformatting - leaksterrr