FormatStrings not working with @bind-value:format for <InputNumber> in Blazor WebAssembly #30567
Description
Describe the bug
Display Formatting doesn't work with decimal
types in Blazor WebAssembly.
To Reproduce
- Create a New Blazor Web Assembly App.
- Navigate to Index.razor
- Paste the below code.
<EditForm Model="@exampleModel" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<InputNumber id="name" @bind-Value="exampleModel.Price" @bind-Value:format="{0:#.##}" />
<button type="submit">Submit</button>
</EditForm>
@code
{
protected ExampleModel exampleModel = new ExampleModel
{
Price = 580.471m
};
protected void HandleValidSubmit()
{
}
public class ExampleModel
{
//[DisplayFormat(DataFormatString = "{0:#.##}", ApplyFormatInEditMode = true)]
public decimal Price { get; set; }
}
}
-
@bind-value:format
doesn't seem to work. I have also tried with[DisplayFormat(DataFormatString = "{0:#.##}", ApplyFormatInEditMode = true)]
Data Annotation. This also doesn't work. -
Later from the docs I noticed that
Data binding works with DateTime format strings using @Bind:format. Other format expressions, such as currency or number formats, aren't available at this time.
Is there any plans on including this in preview release? Please can you share an update on this? Or is there any best workaround for this at the moment?