MudBlazor / MudBlazor

Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
http://mudblazor.com
MIT License
8.03k stars 1.28k forks source link

MudNumericField autocorrects invalid input using wrong decimal separator instead of just validating #8937

Open jiri-panek opened 5 months ago

jiri-panek commented 5 months ago

Bug type

Component

Component name

MudNumericField

What happened?

MudNumericField autocorrects invalid input instead of just validating. It is way worse situation to autocorrect number with digits after unsupported decimal separator without user noticing, than just leave the value untouched with validation message.

Prime example is using MudNumericField for currency input. Application could switch between different CultureInfo settings or the user could use their local decimal separator. When the decimal separator is different, then the culture currently set, MudNumeric field autocorrects input value for example from 123,5 to 1235 which could be a big problem.

This autocorrect behavior should not be set by default, or at least there should be option to disable it.

Update:

Maybe it is not incorrect behaviour, since I am using en-US culture and ',' character is used as CultureInfo.NumberFormat.CurrencyGroupSeparator and CultureInfo.NumberFormat.NumberGroupSeparator.

With my culture settings, we use ',' as a decimal separator. So it's easy to make a mistake. So while the autocorrect function may not be wrong, I would still like to have a way to disable this autocorrect behavior. Instead I would rather call validation method.

Expected behavior

MudNumericField does not autocorrect invalid value.

Reproduction link

https://try.mudblazor.com/snippet/wOweOTbkmigbVTCr

Reproduction steps

  1. Input decimal value with at least one non-zero digit after decimal separator into MudNumericField using different separator than CultureInfo.CurrentCulture is using, for example if en-US culture is set, use ',' as decimal separator. Input for example "0,5" if CurrentCulture is using different separator than ','.
  2. Switch focus using tab or just click some other page element (button).
  3. See how MudNumericField autocorrected value with simply removing decimal separator.

Relevant log output

No response

Version (bug)

6.19.1

Version (working)

No response

What browsers are you seeing the problem on?

Edge

On which operating systems are you experiencing the issue?

Windows

Pull Request

Code of Conduct

daveHylde commented 2 weeks ago

May be related to #10031