Nullable Integer RadzenNumeric allows decimals #1554

Closed
opened 2026-01-29 17:55:20 +00:00 by claunia · 0 comments
Owner

Originally created by @cohenjw on GitHub (Dec 24, 2024).

Describe the bug
If you bind a RadzenNumeric to a nullable integer, it does not format a decimal input (you can insert a decimal by pasting).
On the contrary, binding to a non-nullable integer will correctly format it to 0, as expected.
This value in the nullable integer field also sets off RadzenRequiredValidator, implying that the value behind correctly has no value, but it's not updating visually.

To Reproduce
The following code snippet should help demonstrate the problem:

<RadzenTemplateForm Data="@_model">
    <RadzenRow>
        <RadzenColumn Size="2">
            <RadzenLabel Component="Age" Text="Age" />
            <RadzenNumeric Name="Age" @bind-Value=@_model.Age InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", "enter value" }})" />
            <RadzenRequiredValidator Component="Age" Text="Age is required." />
        </RadzenColumn>

        <RadzenColumn Size="2">
            <RadzenLabel Component="AgeNullable" Text="Nullable Age" />
            <RadzenNumeric Name="AgeNullable" @bind-Value=@_model.AgeNullable InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", "enter value" }})" />
            <RadzenRequiredValidator Component="AgeNullable" Text="Age is required." />
        </RadzenColumn>

        <RadzenButton ButtonType="ButtonType.Submit" Text="Submit">
    </RadzenRow>
</RadzenTemplateForm>

@code {
    private Model _model = new();

    public class Model {
        public int Age;
        public int? AgeNullable;
    }
}
  1. Clicking submit correctly raises the nullable integer's RadzenRequiredValidator, and not the non-nullable integer's due to its default being 0, and always having value.
  2. Attempting to paste a decimal value, such as 2.22, into the non-nullable field, results in the value being formatted to default(int)
  3. Attempting to paste a decimal value, such as 2.22, into the nullable-bound field, results in no formatting of the value (expected default(int?)).
  4. Submitting the form at this stage still triggers RadzenRequiredValidator, despite there being value in the field. (It just needs visually updating, clearly).

Expected behavior
I'd expect a RadzenNumeric bound to an integer (nullable or not) to not allow decimals under any circumstances. The nullable-bound input should format to default(int?) which is of course null.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Win11
  • Browser: Chrome
  • Version: 131.0.6778.205

Additional context
Radzen version 5.7.1

Originally created by @cohenjw on GitHub (Dec 24, 2024). **Describe the bug** If you bind a RadzenNumeric to a nullable integer, it does not format a decimal input (you can insert a decimal by pasting). On the contrary, binding to a _non-nullable_ integer will correctly format it to 0, as expected. This value in the nullable integer field also sets off RadzenRequiredValidator, implying that the value behind correctly has no value, but it's not updating visually. **To Reproduce** The following code snippet should help demonstrate the problem: ```cs <RadzenTemplateForm Data="@_model"> <RadzenRow> <RadzenColumn Size="2"> <RadzenLabel Component="Age" Text="Age" /> <RadzenNumeric Name="Age" @bind-Value=@_model.Age InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", "enter value" }})" /> <RadzenRequiredValidator Component="Age" Text="Age is required." /> </RadzenColumn> <RadzenColumn Size="2"> <RadzenLabel Component="AgeNullable" Text="Nullable Age" /> <RadzenNumeric Name="AgeNullable" @bind-Value=@_model.AgeNullable InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", "enter value" }})" /> <RadzenRequiredValidator Component="AgeNullable" Text="Age is required." /> </RadzenColumn> <RadzenButton ButtonType="ButtonType.Submit" Text="Submit"> </RadzenRow> </RadzenTemplateForm> @code { private Model _model = new(); public class Model { public int Age; public int? AgeNullable; } } ``` 1. Clicking submit correctly raises the nullable integer's RadzenRequiredValidator, and not the non-nullable integer's due to its default being 0, and always having value. 2. Attempting to paste a decimal value, such as 2.22, into the non-nullable field, results in the value being formatted to `default(int)` 3. Attempting to paste a decimal value, such as 2.22, into the nullable-bound field, results in no formatting of the value (expected `default(int?)`). 4. Submitting the form at this stage still triggers RadzenRequiredValidator, despite there being value in the field. (It just needs visually updating, clearly). **Expected behavior** I'd expect a RadzenNumeric bound to an integer (nullable or not) to not allow decimals under any circumstances. The nullable-bound input should format to `default(int?)` which is of course null. **Screenshots** If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: Win11 - Browser: Chrome - Version: 131.0.6778.205 **Additional context** Radzen version 5.7.1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1554