I have not used Knockout in a while and am running into an issue when trying to trim the input value of a form field to two decimal places. I created the below computed observable and am subscribing to it by the observable that I want to update with the trimmed value. Can anyone tell me what I am doing wrong?
View Model
function createViewModel() {
var self = {};
self.SalesRepId = ko.observable().extend({ required: true });
self.PriceAdvanced = ko.observable("").extend({ required: true, min: 1, max: 200 });
self.decimalValue = ko.computed(function () {
var num = self.PriceAdvanced().slice(0, (self.PriceAdvanced().indexOf(".")) + 3);
return num;
}).extend({ notify: "always" });
self.PriceAdvanced.subscribe(self.decimalValue);
return self;
}
HTML:
<div class="form-group col-xs-12">
<label class="label-col col-xs-4 control-label labelFormat" for="PriceAdvanced"><span class="warn">* </span>Advanced Criminal History Search</label>
<div class="col-xs-8">
<input class="form-control max225" type="text" id="PriceAdvanced" name="PriceAdvanced" data-bind="textInput: PriceAdvanced" size="23" placeholder="$0.00" />
</div>
</div>