Unplanned
Last Updated: 19 Nov 2021 08:56 by ADMIN
Connor
Created on: 12 Nov 2021 12:21
Category: NumericTextBox
Type: Bug Report
5
Cannot select 0 as first value via the arrow keys/buttons if the NumericTextBox is bound to nullable type

Hi,

I have found a bug with the TelerikNumericTextBox in that it doesn't function correctly with nullable types (at least it doesn't with Nullable<int>). I have confirmed this is the case for both 2.28 and 2.29 versions of Kendo for Blazor.

Description of the issue:

If "TelerikNumericTextBox" is "@bind-Value" to a nullable int, the control exhibits some unusual behaviour. If you manually type 0 into the control, it is accepted and the value updates the view-model property. However, if you use either the down-arrow button or arrow keys to select 0 (on a fresh load so there is no existing value selected/set), it does not set/update the view-model property. However, it does work correctly if you select another value first (such as 1) and then select 0.

Unfortunately, this is confusing the end-users of my application and I believe it is a bug (I haven't noticed this when using the Kendo for Angular or Kendo for JQuery).

In my application, I need users to be able to set the value of 0 but we do not want to set an initial value for the NumericTextBox to be 0 as this could lead our customers on; the application in question is requiring the end-user to manually select the number rather than allowing them to just leave it as default. Therefore, the view-model property I am binding to has been put as "int?" so that the default value is null and validation will require the user to select a valid value if they just try and press save without making any changes. Please note, for our use case, the number 0 is a valid option!

Steps to reproduce the issue:

Use the following razor HTML

The new value is: @TheValue

<TelerikNumericTextBox Format="D" Max="10" Min="0" Step="1" @bind-Value="@TheValue"></TelerikNumericTextBox>

@code {
    public int? TheValue { get; set; }
}

Click into the control and either press "down" on the keyboard arrow keys or press the "down" icon next to the control, so the value is set to be 0. The number 0 will not be set/persisted to the view-model property even though the control shows a 0 value.

If you have multiple controls on the page, following the above steps will mean that as soon as you click into another control, 0 is deleted (I believe because the VM prop has not been set), this does not happen if you type 0 into the control.

HOWEVER

If you continue to use the same Razor code above and any of the following workflows, it will set the controls view-model property correctly:

  • Type 0 into the control - value is set correctly and property on the view-model is updated
  • Select "up" on the keyboard (so the value is 1) and then press down (so the value is 0) - 0 is set correctly and property on the view-model is updated
  • Select "up" on the numeric textbox's up arrow button (so the value 1) and then press "down" on the down arrow button (so the new value is 0) - 0 is set correctly and property on the view-model is updated

Additional notes:

  • I have noticed this only seems to apply to the nullable version of the int type, if the prop is just an int, the control works fine but is automatically defaulted to 0 (which is not appropriate for my use case)
  • It seems that as soon as the control/view model property has an initial value, the control behaves normally and the issue no longer happens anymore (both with keyboard navigation and the control's up/down buttons).
  • I have not tested with any other types/primitives, just on INT so far
  • I have confirmed this happens if you have the control in an "<EditForm/>" or outside of an EditForm. 

I have attached a sample project where I have replicated the issue, it is just a simple NET5 WASM Blazor project (generated from the default template) and I have just added the latest Kendo for Blazor. Nothing else has been done except for demoing on the "index.razor" both binding approaches I have tried/been able to replicate this issue on.

 

I hope the above makes sense, let me know if you need any further clarification.

2 comments
ADMIN
Nadezhda Tacheva
Posted on: 19 Nov 2021 08:56

Hi Connor,

Thank you very much for the detailed description of the issue, runnable sample and steps to reproduce it!

Indeed, this is a valid bug and it also can be reproduced with other nullable types (decimal?, double? etc.) in addition to nullable int. Thank you for noticing and reporting this behavior!

I logged an internal issue and linked it to this item. Thus, their statuses will be synchronized and as creator of the post you will be notified via email when its status changes. This is the best way to keep in track with the progress of the bug as once we know which release will contain its fix, we will update its status right away.

In addition, I tweaked the title a bit to cover the exact scenario.

Last but not least, as a small token of appreciation for your report, I have rewarded your account with some Telerik points.

Regards,
Nadezhda Tacheva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Connor
Posted on: 12 Nov 2021 12:25

I thought I gave this a better subject. Unfortunately, it won't let me change this retrospectively. 

Apologies for this. If you are able to change this to something more meaningful (such as "TelerikNumericTextBox - Does not allow setting 0 via keyboard/buttons for nullable types") that'd probably be better.

Sorry again.