on the line allBindings = allBindings.value().extend({ numericNotNegative: '' }); ?
I have an extender that works correctly called numericNotNegative and I just want to make a custom binding that applies it to the observable passed into value.
Please help.
Thanks!
My code:
ko.extenders.numericNotNegative = function (target) {
//create a writeable computed observable to intercept writes to our observable
var result = ko.computed({
read: function () {
if (target() == "0")
return '';
else
return target();
}, //always return the original observables value
write: function (newValue) {
var current = target();
var realNumber = rawNumber(newValue.toString().replace("-", ""));
var valueToWrite = number_format(realNumber);
//only write if it changed
if (valueToWrite !== current) {
target(valueToWrite);
} else {
//if the rounded value is the same, but a different value was written, force a notification for the current field
if (newValue != current) {
target.notifySubscribers(valueToWrite);
}
}
}
});
//initialize with current value to make sure it is rounded appropriately
result(target());
//return the new computed observable
return result;
};
ko.bindingHandlers.numeric = {
init: function (element, valueAccessor, allBindingsAccessor, passedInViewModel) {
var allBindings = allBindingsAccessor();
if (valueAccessor()) {
allBindings = allBindings.value().extend({ numericNotNegative: '' });
}
}
}