SfNumericTextBox - Currency="AUD"

Hi,

I have a numeric text box declared as follows

 <SfNumericTextBox TValue="Decimal" ValidateDecimalOnType=true Decimals=2 Format="c2"
                                                                          @bind-Value="@chargeBreak.Minimum"
                                                                          Min=0 Placeholder="0.00" Currency="AUD">
                                                        </SfNumericTextBox>

but I am getting the following error
System.Exception: The given key 'AUD' was not present in the dictionary.
   at Syncfusion.Blazor.Internal.Intl.GetNumericFormat[Decimal](Decimal numberValue, String format, String culture, String currencyCode)
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].formattedValue(Nullable`1 decimals, Decimal value)
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].validateMinMax()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<OnParametersSetAsync>d__294[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)


Documentation on the Currency field says that possible values come from ISO4217, and I it appears that AUD is declared in this ISO.

Thanks,
Jerwmy


14 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team March 26, 2021 11:36 AM UTC

Hi Jeremy, 

Greetings from Syncfusion support. 

We would like to inform you that, you can change the formatting based on the CLDR-data to C# cultureInfo based formatting. So, we need to set the currency code in the startup.cs file as mentioned below code example to render the Numeric TextBox component with corresponding culture. 

public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddRazorPages(); 
            services.AddServerSideBlazor(); 
            services.AddSingleton<WeatherForecastService>(); 
            services.AddSyncfusionBlazor(); 
            services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SampleLocalizer)); 
            services.Configure<RequestLocalizationOptions>(options => 
            { 
                // Define the list of cultures your app will support 
                var supportedCultures = new List<CultureInfo>() 
                { 
                    new CultureInfo("en-US"), 
                    new CultureInfo("en-AU") 
                }; 
 
                // Set the default culture 
                options.DefaultRequestCulture = new RequestCulture("en-AU"); 
                options.DefaultRequestCulture.Culture.NumberFormat.CurrencySymbol = supportedCultures[1].NumberFormat.CurrencySymbol; 
 
                options.SupportedCultures = supportedCultures; 
                options.SupportedUICultures = supportedCultures; 
                options.RequestCultureProviders = new List<IRequestCultureProvider>() { 
                 new QueryStringRequestCultureProvider() // Here, You can also use other localization provider 
                }; 
            }); 
        } 

<SfNumericTextBox TValue="Decimal" ValidateDecimalOnType=true Decimals=2 Format="c2" @bind-Value="@chargeBreak" Min=0 Placeholder="0.00"> 
</SfNumericTextBox> 
 
@code { 
    public Decimal chargeBreak; 
} 

Output: 
 
 


Please find the documentation from the below link.  

Please get back us if you need further assistance. 

Regards, 
Ponmani M 



JE Jeremy March 27, 2021 07:22 AM UTC

HI, thanks for the response,

I have added you example code but I am still getting the following exception

System.Exception: The given key 'AUD' was not present in the dictionary.
   at Syncfusion.Blazor.Internal.Intl.GetNumericFormat[Decimal](Decimal numberValue, String format, String culture, String currencyCode)
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].formatNumber()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<modifyText>d__304[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<changeValue>d__300[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<OnInitializedAsync>d__293[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

I dont think you answered my question


"Documentation on the Currency field says that possible values come from ISO4217, and I it appears that AUD is declared in this ISO."

So I am confused as to what I am missing when using the Currency field please?



PM Ponmani Murugaiyan Syncfusion Team March 29, 2021 11:16 AM UTC

Hi Jeremy, 

Thanks for the update. 

From your provided information we understand that you are still facing console error in NumericTextBox component. But we quite unclear about the exact scenario your facing the reported issue. Also, with your provided code snippet, we couldn’t replicate the issue in our end and attached the ensured sample, video demonstration below for your reference. 



So kindly share the following details: 
   
  1. Share your Syncfusion.Blazor Nuget package version details.
  2. Share the video demonstration of the issue along with replication procedure.
  3. Are you facing the reported issue in during initial rendering itself or during a certain action?
  4. Share simple issue replicating sample.
   
Above requested details will be helpful for us to validate the reported query at our end and provide better solution as early as possible. 

Regards, 
Ponmani M 


Marked as answer

JE Jeremy March 30, 2021 07:51 AM UTC

I see your sample is a Blazor Server app.

Can you please try the same with a .Net5 Blazor Client app?

Attachment: WebApplication2_18f9aa03.zip


PM Ponmani Murugaiyan Syncfusion Team March 31, 2021 03:48 PM UTC

Hi Jeremy, 

Thanks for providing the sample. Currently we are checking the reported issue and will update further details in 2 business days. 

Regards, 
Ponmani M 



JE Jeremy replied to Ponmani Murugaiyan April 8, 2021 09:24 AM UTC

Hi Jeremy, 

Thanks for providing the sample. Currently we are checking the reported issue and will update further details in 2 business days. 

Regards, 
Ponmani M 


Hi, just following up if there has been any progress please?


PM Ponmani Murugaiyan Syncfusion Team April 8, 2021 10:28 AM UTC

Hi Jeremy, 

Thanks for your patience. 

As per our previous update, we suggest you to remove the currency property from component and set the default culture in Program.cs file to get the Numeric TextBox component with desired currency symbol. Please find the documentation for enabling Localization with WebAssembly application. Also attached the sample with WebAssembly .NetCore 5.0 for your reference. 



<SfNumericTextBox TValue="Decimal" ValidateDecimalOnType=true Decimals=2 Format="c2" 
                  @bind-Value="@chargeBreak" Min=0 Placeholder="0.00"> 
</SfNumericTextBox> 
 
<SfNumericTextBox TValue="Decimal" ValidateDecimalOnType=true Decimals=2 Format="c2" 
                  @bind-Value="@chargeBreak" 
                  Min=0 Placeholder="0.00"> 
</SfNumericTextBox> 
 
@code{ 
    public Decimal chargeBreak { get; set; } 
} 

public static async Task Main(string[] args) 
        {  
            var builder = WebAssemblyHostBuilder.CreateDefault(args); 
            builder.RootComponents.Add<App>("#app"); 
            builder.Services.AddSyncfusionBlazor(); 
            builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); 
 
            // Set the default culture of the application 
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-AU"); 
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-AU"); 
 
                        // Get the modified culture from culture switcher 
                        var host = builder.Build(); 
                        var jsInterop = host.Services.GetRequiredService<IJSRuntime>(); 
                        var result = await jsInterop.InvokeAsync<string>("cultureInfo.get"); 
                        if (result != null) 
                        { 
                            // Set the culture from culture switcher 
                            var culture = new CultureInfo(result); 
                            CultureInfo.DefaultThreadCurrentCulture = culture; 
                            CultureInfo.DefaultThreadCurrentUICulture = culture; 
                        } 
 
            builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 
 
            await builder.Build().RunAsync(); 
        } 

 

Kindly check with the above suggestion in your application to get rid of this issue. Please get back us if you need further assistance. 

Regards, 
Ponmani M 



JE Jeremy April 8, 2021 11:32 AM UTC

Thanks Ponmani,

I will give that a try, but I believe your suggestion is a work around to the issue and you havent actually explained why my example code is raising an exception?

Note in your reply on March 29 you said

"From your provided information we understand that you are still facing console error in NumericTextBox component. But we quite unclear about the exact scenario your facing the reported issue. Also, with your provided code snippet, we couldn’t replicate the issue in our end and attached the ensured sample, video demonstration below for your reference."

I downloaded your sample code from this response and verified that the property worked - but your sample code was a Blazor Server solution. 

I then demonstrated that the same code raised the exception when used in a Blazor Client application.

Are you suggesting that the "currency" property is only supported for Server side blazor?

Your response indicates that the "currency" property is not to be used? Does that mean it is obsolete, no longer being maintained or only has limited functionality with server side blazor? If so is there documentation that highlights this, as the comment for the function doesnt make this obvious. 



Jeremy


PM Ponmani Murugaiyan Syncfusion Team April 12, 2021 02:10 AM UTC

Hi Jeremy, 

Thanks for the update. 

We would like to inform you that from the release version (18.1.42), we have changed the formatting based on the CLDR-data to C# cultureInfo based formatting. So, we need to set the currency code in the startup.cs file for Server app and in program.cs file for Client app file as mentioned in our previous update to render the Numeric TextBox component with corresponding culture and currency code. 

Please find the below release notes for more information. 

   
Also, we have provided support for localization using its own way of ASP.Net core approach. Please find the NumberFormat properties from the below .NET Core documentation link.  


Regards, 
Ponmani M 



JE Jeremy April 18, 2021 07:53 AM UTC

Hi,

I dont believe you directly answered any of the questions in my previous post. Can you please escalate this to another support person?

Can you please provide me with an example of a Blazor WASM application (your previous example was a server application) that uses the "currency" property.

I have attached an example WASM project where I have used the suggested code (services.Configure<RequestLocalizationOptions> and I am still getting the following exception

System.Exception: The given key 'AUD' was not present in the dictionary.
   at Syncfusion.Blazor.Internal.Intl.GetNumericFormat[Decimal](Decimal numberValue, String format, String culture, String currencyCode)
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].formatNumber()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<modifyText>d__304[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<changeValue>d__300[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Syncfusion.Blazor.Inputs.SfNumericTextBox`1.<OnInitializedAsync>d__293[[System.Decimal, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

can you please tell me what I am missing from my code example that is causing this exception?

Attachment: NumericTextBoxCurrency_7034c877.zip


PM Ponmani Murugaiyan Syncfusion Team April 21, 2021 01:26 PM UTC

Hi Jeremy, 

Sorry for the inconvenience caused. 

We have modified your provided sample by enable Localization in Blazor WebAssembly application .Net 5.0 as like given in the below documentation link. Please follow the added steps below: 


1. Add the Localization service configuration in the ~/Program.cs file. 

// Register the Syncfusion locale service to customize the  SyncfusionBlazor component locale culture 
builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); 
 
// Set the default culture of the application 
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-AU"); 
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-AU"); 
 
// Get the modified culture from culture switcher 
var host = builder.Build(); 
var jsInterop = host.Services.GetRequiredService<IJSRuntime>(); 
var result = await jsInterop.InvokeAsync<string>("cultureInfo.get"); 
if (result != null) 
  { 
       // Set the culture from culture switcher 
       var culture = new CultureInfo(result); 
       CultureInfo.DefaultThreadCurrentCulture = culture; 
       CultureInfo.DefaultThreadCurrentUICulture = culture; 
} 

2. Create ~/Shared/SyncfusionLocalizer.cs file and implement ISyncfusionStringLocalizer to the class. This acts as a middleware to connect the Syncfusion Blazor UI components and resource files 

Note: Map the SfResources.ResourceManager to this interface Manager 

namespace NumericTextBoxCurrency.Shared 
{ 
    public class SyncfusionLocalizer : ISyncfusionStringLocalizer 
    { 
        // To get the locale key from mapped resources file 
        public string GetText(string key) 
        { 
            return this.ResourceManager.GetString(key); 
        } 
 
        // To access the resource file and get the exact value for locale key 
 
        public System.Resources.ResourceManager ResourceManager 
        { 
            get 
            { 
                return NumericTextBoxCurrency.Resources.SfResources.ResourceManager; 
            } 
        } 
    } 
} 

Note: For .NET 5.0 Blazor Webassembly globalization, we should configure the BlazorWebAssemblyLoadAllGlobalizationData in the project file when the application uses large resources and dynamic culture changes. 

  <PropertyGroup> 
    <TargetFramework>net5.0</TargetFramework> 
  <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData> 
  </PropertyGroup> 

3. Add the resource files in the ~/Resources folder. The locale resource files for different cultures are available in this GitHub repository. You can get any culture resource file from there and utilize it in your application. 

4. Add the custom JavaScript interop function to get or set the culture in ~/wwwrooot/index.html 

<script> 
        window.cultureInfo = { 
            get: () => window.localStorage['BlazorCulture'], 
            set: (value) => window.localStorage['BlazorCulture'] = value 
        }; 
</script> 

[Index.razor] 
 
<SfNumericTextBox TValue="Decimal" ValidateDecimalOnType=true Decimals=2 Format="c2" @bind-Value="@charge" Min=0 Placeholder="0.00"></SfNumericTextBox> 
 
@code 
{ 
       public Decimal charge { get; set; } 
} 

Output: 
 
 


Regards, 
Ponmani M 



JE Jeremy April 22, 2021 12:27 AM UTC

why havent you used the currency property?



and you have done is give me a workaround for the issue.

What is the reason you could not escalate this question to someone else? I would like someone else to look at my original post and my sample code please.


PM Ponmani Murugaiyan Syncfusion Team April 22, 2021 05:51 PM UTC

Hi Jeremy, 

Sorry for the inconvenience caused. 

Currently we are investigating further on your reported query. We will update further details in 2 business days (April 26, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 



PM Ponmani Murugaiyan Syncfusion Team April 26, 2021 04:57 PM UTC

Hi Jeremy, 

Thanks for the update. 

We have validated and considered the reported console error “System.Exception: The given key 'AUD' was not present in the dictionary” as a bug in our end and the fix will be included in Volume 1 SP1 release which is expected to be rolled out on mid of May 2021. You can track the status using the below feedback link. 


Also, we would like to know you that by loading the culture in your application the respective currency will be loaded in the Numeric TextBox. As per the culture “en-AU”, the below currency symbol will be loaded based on application. 

Server side 
Client side 
AUD 

As per c# standard en-AU currency symbol is $ and in server side it will be returned $ as expected. But in WASM application, it returned currency symbol as "AUD". This is WASM application issue and already logged this as bug. Please find the GitHub forum. 


Regards, 
Ponmani M 


Loader.
Up arrow icon