Numeric doesn’t show entry

Hi.

Problem looks similar to this one

Here's the way I used this component

<RadzenNumeric TValue="double" Step="0,5" Placeholder="Enter weight in kilograms" @bind-Value="@ProductVariant.Weight" Style="margin-bottom: 20px" />

Problem occurs when Numeric tries to display a number with decimal part, eg. 12.5 - field stays empty or displays placeholder (when placeholder is configured).
Everything works fine, when value to display is integral, eg. 4

Issue cannot be reproduced in online demo, because @bind-Value is not used there in combination with double datatype.

Here's what I figured out so far.

  1. Step attribute has to be passed using current locales number format (setting DecimalSeparator and ThousandSeparator has no effect). Otherwise the following exception is thrown :

Error: System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Double.Parse(String s)
at Radzen.Blazor.RadzenNumeric1.UpdateValueWithStep(Boolean stepUp) at Radzen.Blazor.RadzenNumeric1.b__0_0(MouseEventArgs args)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

  1. If Step attribute is parsed sucessfully, bound value is updated properly, but...
  2. When value is not integral (contains fractional part) Numeric does not display value (empty field or configured placeholder is displayed). Setting DecimalSeparator and ThousandSeparator has no effect.
  3. Typing value with .(dot) as well as ,(comma - my current locale) as decimal separator updates value accordingly

Could you look into this?


EDIT:
To illustrate the problem, below is behavior of RadzenInput I am experiencing:

I have placed RadzenInput next to input (asp.net core component). Both controls are bound to the same variable.
Please note that RadzenInput needs ,(comma) as Step value, whereas step of input requires .(dot)

<RadzenNumeric TValue="decimal" Step="0,5" Placeholder="Enter weight in kilograms" @bind-Value="@ProductVariant.Weight" />
<input type="number" step="0.5" placeholder="Enter weight in kilograms" @bind-value="@ProductVariant.Weight"/>

Now - the displaying problem... Initial state looks like below:

obraz

When value is changed with arrow buttons (using input) - the new state looks like below:
obraz

Change once again...
obraz

Hi @gpos,

The Radzen Numeric component renders the Step property as the step attribute of the underlying <input type="number">. The latter doesn't support comma as value - only dot. The default step value is "any" which allows both integer and decimal values.

Thanks for response,

The latter doesn't support comma as value - only dot.

Exactly - that is behavior of RadzenInput I was expecting - but I have to use my local decimal separator (comma) in order to some parsing method not to fail with exception.

Can you look into displaying problem as well ?

Exactly - that is behavior of RadzenInput I was expecting - but I have to use my local decimal separator (comma) in order to some parsing method not to fail with exception.

The Numeric uses .NET to parse a number from a string. And .NET adheres to the current culture when doing parsing. The Step property isn't parsed. To be honest you shouldn't really set Step at all - the default value allows decimal numbers.

I stand corrected. There is a Parse going on which is probably causing the problem. Try not setting the Step to see if it makes a difference.

I have found workaround for problem of parsing. I leveraged .net sticking to specific culture. Step expects a string so you can set Step property using ToString() function which uses whichever locale is set

Step="@((0.5).ToString())"

Displaying problem remains...

This will still set Step to 0,5 which is invalid value for the step html attribute. What happens if you set Step to "any" or not set it at all? Radzen should render step="any" in this case.

I know this is invalid, but somehow it is required!


EDIT: it is required for server part of application to work. HTML is rendered with step=0,5 Luckily browser can interpret this as valid numer and Numeric works.


If i use Step="any" - Radzen works as expected with this configuration:

  • Increment is set to 1
  • Data can be entered using current locale, dot as decimal point is working as well.

I think if method parsing Step attribute used InvariantCulture instead of current locale this issue could be resolved.

Pursuing issue further...

I changed my locale to something using dot as decimal separator (en-US, prevoiusly i was using pl-PL) - and BANG! - everything works as it should have been. Even value with fractional part is displayed correctly.

There is internationalization problem present in this control.
The simplest way to reproduce the problem is to change locale of environment running IIS to one using comma (or something else) as decimal separator.

Is it possible to resolve this issue soon ?

Hi @gpos,

We will do our best to provide better internationalization for our numeric component however I'm not sure if it will be quickly. Most probably we need to rewrite it to not use input type='number'. More info here:

I think we found a solution and we will release new version later today.

Solution, whatever it is - works.
Thank You.

It was released yesterday.