0
function ProductViewModel()
{
var self = this;

self.Amount= ko.observable(0);

self.Quantity= ko.observable(0);
}

ko.extenders.numeric = function(target, precision) {
var result = ko.computed({
    read: target,  
    write: function(newValue) {
      var value = parseFloat(newValue,10);
      if(precision > 0){
        target(value.toFixed(precision));
      }
      else{
        target(Math.round(value));
      }
    }
});

result(target());

return result;
};

ko.applyBindings(new ProductViewModel());

Now i want to add extenders dynamically after observable is created not at a time of declaration ? I also fetching data from server and converting to observable using ko.mapping.fromJS(data) and after that i want to add extenders...so guide me guys....

Nilesh Moradiya
  • 691
  • 1
  • 10
  • 19

1 Answers1

0

Is the problem that your defined extender isn't working? It looks like you are missing a call to ko.validation.registerExtenders();

Put the above line just before you call applyBindings

Tom Studee
  • 10,316
  • 4
  • 38
  • 42