LP13
LP13

Reputation: 34109

Copy paste numbers with comma in Kendo numeric text box

I have kendo numeric text box. If i type number like 123456, the widget automatically format the number with comma and dollar symbol as expected. However if i copy and paste number with comma, for example 123,456, the widget does not accept that as input.

JSfiddle demo

How do i fix this or override the defualt behavior

Upvotes: 0

Views: 1551

Answers (2)

Meghana
Meghana

Reputation: 11

place comma by separated thousand value and place currency of country for Kendo grids

columns.Bound(e => e.Amount).ClientTemplate("#= Amount !== null ? kendo.toString(Amount, 'c', 'en-US') : ''#").Width("5%").Title("Amount"); For instance:

kendo.toString(1234.23, ‘c’, ‘de-DE’) –> 1.234,23 €

kendo.toString(1234.23, ‘c’, ‘sv-SE’) –> 1.234,23 kr

kendo.toString(1234.23, ‘c’, ‘en-US’) –> $1,234.23

only comma separated with two decimal points: columns.Bound(e => e.Amount).ClientTemplate("#= kendo.format('{0:N2}', kendo.toString(Amount)) #").Width("5%").Title("Amount"); for Example - 1234.44 -> 1,234.44 1234 -> 1,234.00

Upvotes: 1

The Dread Pirate Stephen
The Dread Pirate Stephen

Reputation: 3169

I think it is a bug in Kendo...

In the source code for the NumericTextBox, there is a _paste handler that appears like it is trying to sanitize the input against the culture's numeric format but then it validates against the unsanitized value...seems to be it should use the sanitized value.

Here's the implementation:

_paste: function (e) {
            var that = this;
            var element = e.target;
            var value = element.value;
            var numberFormat = that._format(that.options.format);
            setTimeout(function () {
                var result = that._parse(element.value);
                var isValid = that._numericRegex(numberFormat).test(element.value);
                if (result === NULL || that._adjust(result) !== result || !isValid) {
                    that._update(value);
                }
            });
        },

So, if you paste "123,456", it will _parse() it to 123456(because it knows that "," is the thousands separator) but then the isValid check is still checking against the "123,456" which is bad and so it reverts to the previous value.

If you change the isValid line to

var isValid = that._numericRegex(numberFormat).test(result);

so that it validates against the sanitized value, then it all appears to work as you expect it to....otherwise I can't really see why the sanitize it in the first place.

I realize that changing the kendo source code it not really a valid solution, but I do believe this is a bug that you may have to work around it until it is fixed.

If you have a kendo license, I would contact their support to verify if it is a bug or not. If you don't have a license, let me know and I will submit a request when I have time as I do have a license.

Upvotes: 0

Related Questions