fluentui-blazor: fix: NumberFields do not support doubles, decimals, floats

πŸ› Bug Report

When inserting a value into a numberfield where the bound value is a double, float or decimal, will not allow the user to enter a value with a decimal. It will instead ask you to enter one the the 2 nearest integers.

πŸ’» Repro or Code Sample

<EditForm EditContext="EditContext">
    <DataAnnotationsValidator />
    <FluentNumberField @bind-Value="ExampleModel.Test" Label="Test" />
    <FluentButton Type="ButtonType.Submit">
        Submit
    </FluentButton>
</EditForm>

@code {
    EditContext EditContext { get; set; } = default!;
    Model ExampleModel { get; set; } = new Model();

    protected override void OnInitialized()
    {
        base.OnInitialized();
        EditContext = new EditContext(ExampleModel);
    }

    public class Model
    {
        public double Test { get; set; }
    }
}

πŸ€” Expected Behavior

Allows user to submit the form with a value with decimals

😯 Current Behavior

When submitting the form, we get this preventing form submission. image

πŸ’ Possible Solution

πŸ”¦ Context

I have produced a minimal repro (above) in the base template after having found the issue in my main project in order to isolate it.

🌍 Your Environment

Windows, Chrome, .net 8, 4.2.1 FluentUI

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (2 by maintainers)

Most upvoted comments

@thebarrettlo I’m in contact with the FAST team again to see what we can do.

@vnbaaij Just to clarify then, we cannot use the NumberField for decimal values whatsoever? I tried setting the step to 0.01 for example and still get the issue (though this would have still been suboptimal, as stepping using the spinner would have been preferable by a different value). All the same though, I am unable in any way, to have the number say β€œ1.2” represented in a NumberField component?

Yes, we are working on that. See https://github.com/microsoft/fluentui-blazor/discussions/3066 and use the search for more

Hi @vnbaaij, I hope you read comments on already closed issues and it is ok to discuss this issue further here.

I also have troubles with the number field and now read your comments, the linked issue and the link provided there. For my application I need a number field with validation (e.g. min/max value) and culture awareness. You now suggest to not use the number field, instead as stated in the provided link a text field with inputmode=numeric should be used. I could now use the FluentTextField and try to set the inputmode with the AddtionalAttributes – maybe the FluentTextField should provide an explicit parameter for that. But in the end, I think I will make no sense to add all those things (min/max value, culture awareness) to the FluentTextField as it is a text field and no number field. Therefore, I see 3 solutions:

  1. Create my own component which handles all those things with support for min/max, culture awareness and custom validation
  2. Change/improve the FluentNumberField to behave like a correct number field and not using <input type="number"> but <input type="text" inputmode="number"> with support for min/max, culture awareness and custom validation, number formatting (scientific, …), integers or floating point, …
  3. Add an additional fluent component to the library with all the features from 2.

From my perspective,

  1. Feels strange. Because I am using a component library which should take care of such β€œevery-day” problems.
  2. Would be the correct thing to do, because everyone using a component library and sees a component NumberField expect such features.
  3. Would also be ok, because the FluentNumberField is a β€œmapping” to the html input number field with all its known β€œissues”. But we have a general component that works as expected.

What do you think about that?