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

7 posts, 0 answers
  1. Emmsa
    Emmsa avatar
    63 posts
    Member since:
    Oct 2006

    Posted 27 Apr Link to this post

    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.

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1766 posts

    Posted 02 May Link to this post

    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.
  3. Emmsa
    Emmsa avatar
    63 posts
    Member since:
    Oct 2006

    Posted 02 May in reply to Viktor Tachev Link to this post

    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?
  4. Emmsa
    Emmsa avatar
    63 posts
    Member since:
    Oct 2006

    Posted 02 May in reply to Emmsa Link to this post

    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+)?".
  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1766 posts

    Posted 05 May Link to this post

    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.
  6. Philippe
    Philippe avatar
    1 posts
    Member since:
    May 2017

    Posted 22 May Link to this post

    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.

  7. Stefan
    Admin
    Stefan avatar
    1134 posts

    Posted 25 May Link to this post

    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 fr-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.
Back to Top