Replace dot by comma automatically in NumericTextBox

Hi

Have you a solution to replace dot in numeric keyboard (numpad) by comma. In french culture the decimal separator is comma, but when we used dot on numpad some application transform this in comma (Excel for example). In my solutions, french culture has been setting succesfully and comma is the decimal separator. But I want to use the dot key on my numpad as comma.

I can use javascript for this of course like this :

var elements = document.getElementsByClassName("e-numerictextbox");
for (var i = 0; i < elements.length; i++) {
    elements[i].addEventListener('keydown', NumericTexboxDotToComma);
}

. . . 

function NumericTexboxDotToComma(event) {
   if (event.key === '.') {
        setTimeout(function () {
            event.target.value += ',';
        }, 4);
        event.preventDefault();
    };
}
    

But I want to know if you have a more elegant and, above all, more integrated alternative in your wonderful EJ2 solution.

Thanks in advance.

5 Replies

SN Sevvandhi Nagulan Syncfusion Team April 22, 2020 12:38 PM UTC

Hi Frederic, 

Greetings from Syncfusion support. 

We converted to comma, if typed the dot in the keyboard and provided code violates(we can type 2 decimal operatior) some numerictextbox behaviour. So we prepared the sample based on the reported requirement. Kindly refer the below code, 

      function onCreated() { 
          var elements = document.getElementsByClassName("e-numerictextbox"); 
          for (var i = 0; i < elements.length; i++) { 
              elements[i].addEventListener('keyup', NumericTexboxDotToComma); 
          } 
 
      } 
      function NumericTexboxDotToComma(event) { 
          if (event.key === '.' && !this.value.includes('.') && !this.value.includes(',')) { 
              this.value += ","; 
          }; 
      } 


Regards, 
Sevvandhi N 



CL Cleber November 26, 2020 01:46 PM UTC

Excuse me for reviving this topic, but why the components do not take advantage of the culture that is used in the application through:

public void Configure (IApplicationBuilder app, IHostingEnvironment env)
{
// Setting the default culture: pt-BR
var supportedCultures = new [] {new CultureInfo ("pt-BR")};
app.UseRequestLocalization (new RequestLocalizationOptions {DefaultRequestCulture = new RequestCulture (culture: "pt-BR", uiCulture: "pt-BR"), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures});

Every time I saw a problem with culture in the components, I think "why not?".


MK Muthukumar Kannan Syncfusion Team December 4, 2020 12:07 PM UTC

Hi Cleber,

Sorry for the delayed response.

We are validating your reported query for Application wise localization for Syncfusion Components in ASP.NET Core. We will update the further details within 1 business day (7th December 2020).

Until then we appreciate your patience.
 
 
Kindly please let us know if you have any concerns.

 
Regards,
Muthukumar K


MK Muthukumar Kannan Syncfusion Team December 7, 2020 06:00 PM UTC

Hi Cleber,
 
Sorry for the inconvenience caused.

We could not able to provide the details for the reported query as we promised. However, we will update the details shortly within 8th December 2020 without any further delay.

Until then we appreciate your patience.

Please let us know if you have any concerns.

Regards,
Muthukumar K


MK Muthukumar Kannan Syncfusion Team December 8, 2020 06:40 PM UTC

Hi Cleber,

Thanks for your patience.

We would like to know that, our ASP.NET Core Syncfusion Components supports localization and globalization based on the CLDR data. So that we recommend using CLDR data localization instead of using Application wide localization. 

However, we can set the culture through the application, and get that culture value, and passed it to setCulture method for set the culture as globally. 

in startup.cs
 public void Configure(IApplicationBuilder appIHostingEnvironment env)
        {
            var supportedCultures = new[] { new CultureInfo("pt-BR") };
            app.UseRequestLocalization(new RequestLocalizationOptions { 
                DefaultRequestCulture = new RequestCulture(culture"pt-BR"uiCulture"pt-BR"), 
                SupportedCultures = supportedCultures
                SupportedUICultures = supportedCultures 
            });
            //other codes
        }

in cshtml,

    var cultureInfo = '@System.Globalization.CultureInfo.CurrentCulture.Name';

    document.addEventListener('DOMContentLoaded'function () {
       // ...
        loadCultureFiles(cultureInfo);
        ej.base.setCulture(cultureInfo); 
        // ...
    });


Please let us know if we misunderstood and have any concerns about this.

Regards
Muthukumar K


Loader.
Up arrow icon