See the following code snippet:
ko.bindingHandlers.currencyFormat = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
ko.utils.registerEventHandler(element, 'keyup', function (event) {
var observable = valueAccessor();
debugger;
observable(formatInput(element.value));
observable.notifySubscribers(5);
});
},
update: function (element, valueAccessor, allBindingsAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).val(value);
}
};
I've been experiencing some problems I am unable to understand why in relation to instances in which I base myself for the extensor knockout FormatCurrency plugin. When I insert the value in the field to be formatted in the change event (which would be to update the value of the field to the value entered) the error is occurring "number is not a function", because as I have seen in debugging, indeed variable "observable" that is created by valueAcessor is a number (this case is 0):
But seeing the example in which I mirrored me, the variable "observable" is not numeric, as can be seen below:
function d(){if(0<
arguments.length)return d.Pa(c,arguments[0])&&(d.X(),c=arguments[0],d.W()),this;a.k.Jb(d);return c}
Anyone have any idea what the problem might be seeing this piece of code?
The html code:
<input id="valorRealizado" class="form-control" data-bind='currencyFormat: ValRealizado' />
I'll try to better explain the scenario. In my application I will load a list of objects, in this case would be the "Andamentos" object. This list of objects comes from my Controller (I'm working with Asp.NET MVC4). The list may come empty or not. In the client-side application, can add (by "viewModel.Andamentos.push ({...})") more items to the list one by one, and save each item individually. Technically I only work with that object twice, to load it (through "viewModel.Andamentos (result.Andamento);") when I add more elements to "Andamentos".