angular-kendo UI, NumericTextBox, cant display zero value

2.3k views Asked by At

When I set initial value of variable to "0", then NumericTextBox field cant show this value.

Code:

<div ng-app="app">
    <div ng-controller="MyCtrl">
        <input type="text" ng-model="value" kendo-numeric-text-box>
            <br>
        <input type="text" ng-model="value">
    </div>
</div>

JS:

angular.module('app', ['kendo.directives']);
function MyCtrl($scope) {
    $scope.value=0;
};

In jsfiddle you can see that simple text field displays zero value, but kendo NumericTextBox is empty. But if you type zero again in simple text field, then zero will be in kendo field too. I think this is a bug, how to get around this problem?

1

There are 1 answers

2
Lars Höppner On BEST ANSWER

Well, if it is a bug, you can either ask the maintainer of angular-kendo to fix it, or you can fix it yourself. It's a relatively simple fix, I think, because the link function doesn't distinguish between model values 0 and undefined. So you'd need to make sure the widget's value method is only called with null if the value is actually null or undefined:

if (typeof ngModel.$viewValue !== 'undefined') {
    widget.value(ngModel.$viewValue);
} else {
    widget.value(null);
}

Here's a demo with a fixed version (links to a fork of angular-kendo, mind you).