Completed
Last Updated: 18 Sep 2019 06:56 by ADMIN
Release 2.0.0
Paul
Created on: 13 Sep 2019 19:36
Category: NumericTextBox
Type: Bug Report
1
When bound to a nullable decimal the NumericTextBox is not setting the decimal? to null when you clear the text box

 

Create a variable like below and bind the numeric text box to it:

 

decimal? myNumber = 9;

decimal? MyNumber

{

   get { return this.myNumber; }

   set { this.myNumber = value; }

}

 

Put a breakpoint on the setter, run the application, and clear out the text box.  The breakpoint will never be hit.  If you enter a numeric value the breakpoint will be hit.  The problem appears to only be with clearing the text box.

6 comments
ADMIN
Marin Bratanov
Posted on: 18 Sep 2019 06:56

Hello Paul,

Yes, this is one of the other issues that we were working on. Both of these should be fixed in the upcoming 2.0.0 release.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
Paul
Posted on: 16 Sep 2019 23:09

Repo for null decimal? Format

 

@page "/numeric"

@using Telerik.Blazor.Components.NumericTextBox

<TelerikNumericTextBox @bind-Value=@Test1  Format="N3"  />

@functions {
    public decimal? Test1 { get; set; } = null;
}

 

 

System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Blazor.Common.Parsers.TelerikGenericDecimal`1.Format(T value, String format)
   at Telerik.Blazor.Components.NumericTextBox.TelerikNumericTextBoxBase`1.get_FormattedValue()
   at Telerik.Blazor.Components.NumericTextBox.TelerikNumericTextBoxBase`1.get_Text()
   at Telerik.Blazor.Components.NumericTextBox.TelerikNumericTextBox`1.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)

 

 

Paul
Posted on: 16 Sep 2019 16:46

I'll put together repro steps for the Format issue I was seeing.

 

As to your workaround with the OnChange handler - that does indeed make sure the backing property is correctly set to null but it's not triggering the built in blazor validation when using an EditForm (it appears EditContext.OnFieldChanged is not being triggered).  In the attached picture Bill Term (a custom component) and Document Date (Telerik date component) are correctly being detected as invalid but the NumericTextboxes are not showing the validation adorner when I set them to null.

ADMIN
Marin Bratanov
Posted on: 16 Sep 2019 16:17

Hello Paul,

The numeric textbox has only the Format parameter, it does not have a DisplayFormat parameter. Could you provide some more details on the issue you are seeing so I can review and evaluate? If you could modify my previous snippet that would help a lot, as it will make sure we are testing the same code and seeing the same behaviors. Adding a short video or a screenshot may also help.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
Paul
Posted on: 16 Sep 2019 15:37

Thanks for the update and work-around.

 

Did you know there is also an issue with DisplayFormat when a value is null?  Is that related?  Is there a different issue to track that?

ADMIN
Marin Bratanov
Posted on: 16 Sep 2019 05:55

Hello Paul,

We are aware of this problem, and we are working on it (it stems from a more complex issue with deleting values, not just nullable fields). You can click the Follow button on this page to get status change notifications.

For the time being, I can offer this workaround to make the field null when OnChange event fires (although it requires blur or enter):

<TelerikNumericTextBox @bind-Value="MyNumber" OnChange="@MyOnChangeHandler"></TelerikNumericTextBox>

@code {
    decimal? myNumber = 9;

    decimal? MyNumber
    {
        get { return this.myNumber; }

        set { this.myNumber = value; }
    }

    private void MyOnChangeHandler(object theUserInput)
    {
        if(theUserInput == null)
        {
            MyNumber = null;
        }
    }
}

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor