This is a migrated thread and some comments may be shown as answers.

Javascript Error when Binding Number with comma to represent a decimal separator

8 Answers 986 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Emmsa
Top achievements
Rank 2
Emmsa asked on 27 Apr 2017, 12:50 PM

Hello,

When I try to bind a NumericTextBox or a CurrencyTextBox to a decimal number, I get in the javascritpt console the following error:
"The specified value "2,5" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?"

The problem seems to be because we use a comma to represent a decimal separator.
I set the culture kendo.culture.es-AR to my layout so the controls should support this.
Can I configure a number format for numeric controls in my proyect to accept a comma for decimal separator?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 02 May 2017, 08:27 AM
Hello Emmsa,

Make sure that you have set matching cultures on the client and server and see how the behavior changes. Check out the following article that illustrates the approach:



With that said, there is a known issue related to similar behavior. You can check it out and observe its status in the link below:



Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Emmsa
Top achievements
Rank 2
answered on 02 May 2017, 01:26 PM
Hello Victor

Thanks for your answer.

The first link is for ASP.NET MVC, I try to do de same in ASP.NET Core but it doesn't work.

I add this key in my app.config:

 <system.web>
     <globalization culture="es-AR" uiCulture="es-AR" />
  </system.web>
  
And this code in my Layout
@{
var culture = System.Globalization.CultureInfo.CurrentCulture.ToString();
}

But the value of culture is always "es-419".

Anyway to test that approach I set a hardcoded culture:

<script src="~/lib/kendo-ui/js/cultures/kendo.culture.es-AR.min.js"></script>
<script src="~/lib/kendo-ui/js/messages/kendo.messages.es-AR.min.js"></script>

<script>
kendo.culture("es-AR");
</script>

But I still get the same error when I assign decimals to the NumericTextBox.

The github link leave me to a page not found, so I couldn't see the known issue.

Any Idea how to fix this error?
0
Emmsa
Top achievements
Rank 2
answered on 02 May 2017, 06:15 PM
In addition, when I set kendo.culture("es-AR") and submit a value within a NumericTextBox it works fine. But when the view loads a model which has a number with decimals,
the NumericTextBox initializes empty and throws the same javascript error: "The specified value "100,5" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?".
0
Viktor Tachev
Telerik team
answered on 05 May 2017, 10:49 AM
Hello Emmsa,

The error you are seeing is observed only in Chrome. The browser flags the value as invalid when comma is used as decimal separator. However, the numeric textbox is working as expected in other browsers.

With that said, the developers are aware of the behavior and will investigate what is causing it.

Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Philippe
Top achievements
Rank 1
answered on 22 May 2017, 06:10 PM

I'm having the same problem as Emmsa. Using decimal/currency for price and fr-CA culture. When I try to post the value, I get « The value '0,45' is invalid. » The same happens in Chrome and IE11.

 

Viktor do you have any solution to bypass the error? Thank you for your time and support.

0
Stefan
Telerik team
answered on 25 May 2017, 12:44 PM
Hello Philippe,

If this is the same error when parsing the value, as a current workaround I can suggest setting the type attribute to text:

.HtmlAttributes(new { style = "width: 100%", type = "text" })

If this does not resolve the issue, please provide a runnable example reproducing the issue with the -CA culture and I will gladly assist.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
khandokar
Top achievements
Rank 1
answered on 02 Feb 2018, 05:32 PM

Hi Stefan,

I have the same problem here. i post today,Please download my runnable example.

sabbir

0
Stefan
Telerik team
answered on 07 Feb 2018, 08:56 AM
Hello, Sabbir,

Thank you for the example.

After I applied the suggested fix with the text attribute the example was working as expected.

var numericTextBox = html.Kendo().NumericTextBox<double>()
.Name("Discount")
.Enable(true)
.Culture("da-DK")
.HtmlAttributes(new { type = "text" })
.Value(4587.25);

Please advise if I missed something.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
NumericTextBox
Asked by
Emmsa
Top achievements
Rank 2
Answers by
Viktor Tachev
Telerik team
Emmsa
Top achievements
Rank 2
Philippe
Top achievements
Rank 1
Stefan
Telerik team
khandokar
Top achievements
Rank 1
Share this question
or