The value in a numeric textbox cannot be changed for negative numerbes unless you erase all the text and restart.
<TelerikNumericTextBox Decimals="4"Max="5"Value="-4.56m"Id="general"></TelerikNumericTextBox>
With
<TelerikNumericTextBox @bind-Value="myValue" Format="C" SelectOnFocus="true">
the content of the input is not selected upon focussing. Without the Format="C" it is.
When SelectOnFocus="true"
is enabled on the NumericTextBox control, and a format (e.g., Format="N1"
) is set, the SelectOnFocus
functionality does not select all text if the decimal value has no trailing digits. For instance, with the value 76
, the text is not selected on focus, but with the value 76.1
, the text is selected correctly.
<TelerikNumericTextBox @bind-Value="@DecimalValue" Format="N1" SelectOnFocus="true"/>
@code {
private decimal DecimalValue = 76;
}
Steps to Reproduce:
SelectOnFocus="true"
.Format="N1"
.76
(with no trailing digits after the decimal point).Expected Behavior:
The entire text (in this case, 76.0
) should be selected when the NumericTextBox gains focus.
Actual Behavior:
The text is not selected when the NumericTextBox gains focus if the value has no trailing digits after the decimal point (e.g., 76
). However, if the value includes trailing digits (e.g., 76.1
), the text is selected as expected.
If I type the maximum value for a decimal (79228162514264337593543950335) and then try to increase the number through the arrow buttons, I get the following exception:
System.OverflowException: Value was either too large or too small for a Decimal.
The behavior is reproducible with or without setting the Max parameter to decimal.MaxValue: https://blazorrepl.telerik.com/mSuFwebI299wPCzV25.
I am creating a wrapper over the TelerikNumericTextBox component so that it works with all numeric data types (such as int, decimal, double, etc). I have added custom parameters for the Min and Max, and if they are not explicitly set I would like them to default to T.MinValue and T.MaxValue respectively.
===ADMIN EDIT===
In the meantime, a possible workaround is to set the "DebounceDelay" parameter to "0".
================
I use 2 different numeric Text Boxes (one for the cost of a product and another for the tax):
The expected behavior that I am trying to get is:
- If I type a cost and leave the field (OnBlur event) then it calculates automatically 5% and set the value for the tax
- However, I want also to allow users to go to the Tax textbox and type a different value (zero for instance)
If I just keep typing different costs the Tax is always calculated and bound correctly as expected:
However, if I go directly to the Tax textbox and type any value there, then this value is always used as a cached value, even if type a new cost and recalculated it:
Eg. Let's say that I typed 10.00 in the tax:
Then if I go to the cost and type 25.00 we would expect that the tax bound variable is 1.25. This is correct while the control still has the focus:
But as soon as I leave the field then the value is reverted back to 10.00:
This is the code that I have:
<div class="form-group col-4">
<label for="prodCost">Cost</label>
<TelerikNumericTextBox Id="prodCost" Arrows="false" T="decimal" Decimals="2" Format="C" Min="0.00m" @bind-Value="@product.Cost" OnBlur="BlurCost" ></TelerikNumericTextBox>
</div>
<div class="form-group col-4">
<label for="prodTax">Tax</label>
<TelerikNumericTextBox Id="prodTax" Arrows="false" T="decimal" Decimals="2" Format="C" Min="0.00m" @bind-Value="@product.Tax"></TelerikNumericTextBox>
</div>
private void BlurCost()
{
var newTax = product.Cost * (decimal)0.05;
product.Tax = newTax;
}
I have a NumericTextBox inside a Grid EditorTemplate. The edit more is InCell.
The OnChange event of the NumericTextBox will not fire if the user tabs out of the NumericTextBox.
The NumericTextBox does not allow pasting from an Excel cell. Pasting from the plain text textbox at the top of the Excel interface works.
The problem is caused by a new line character, which Excel adds to the clipboard value when copying the cell directly. A possible workaround is:
The important thing to keep in mind is: the JavaScript workaround should work only for pasted content, which the NumericTextBox does not allow. Otherwise the app will edit the value one extra time. In the example below, the script checks specifically for a new line at the end of the pasted value.
@inject IJSRuntime js
<TelerikNumericTextBox @bind-Value="@NumValue" Width="200px" Class="fix-paste" />
@* suppress-error allows script tags in Razor components. Move this script to a proper place in production environment. *@
<script suppress-error="BL9992">function fixPaste() {
var inputs = document.querySelectorAll(".fix-paste .k-input-inner");
inputs.forEach(element => {
element.addEventListener("paste", function(e) {
// get pasted content
debugger;
var pastedString = e.clipboardData.getData("text/plain");
// check for specific content, which DOES NOT pass the built-in validation
// adjust this conditional statement, according to the application scenario
if (pastedString.indexOf("\n") == pastedString.length - 1) {
// assign the pasted content manually
e.target.value = pastedString.trim();
// tell the component's .NET instance to change the value
e.target.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
}
});
});
}</script>
@code {
double NumValue { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await js.InvokeVoidAsync("fixPaste");
}
await base.OnAfterRenderAsync(firstRender);
}
}
In versions of Telerik.UI.for.Blazor v2 all the way up to v2.30.0, the NumericTextBox, when provided a Min and Max would display an indication that a number is out-of-range by marking the input as invalid while the focus remained within the input.
After upgrading to v3, the invalid indication no longer happens.
In the attached example project, you'll find that using v3 NumericTextBox with Min=0 and Max=5, does not indicate invalidity if you enter "9" for instance. The input just snaps to 5 when the input loses focus.
If you instead use v2.30.0, it will show the border of the input in red when entering "9".
Subject says it all. I've got a grid that contains multiple NumericTextBoxes.... my users need to be able to copy and paste price values that contain formatting...commas, periods, dollar signs.
Can there be an option to automatically strip off / ignore formatting values in pasted data?
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.
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!
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:
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.
Try with culture es-ES and you will see the problem.
When es-ES, "dot [.]" is not a decimal separator, therefore you can't use the "NumpadDecimal" key to write a decimal number.
@using System.Globalization
<b>Culture:</b> @CultureInfo.CurrentCulture.Name;
<br />
<b>Culture UI:</b> @CultureInfo.CurrentUICulture.Name
<br />
<b>DefaultThreadCurrentCulture:</b> @CultureInfo.DefaultThreadCurrentCulture?.Name
<br />
<b>DefaultThreadCurrentUICulture:</b> @CultureInfo.DefaultThreadCurrentUICulture?.Name
<br /><br />
<b>Val 1:</b>
<TelerikNumericTextBox @bind-Value="@Val1" Decimals="6" Width="100px" />
<TelerikNumericTextBox @bind-Value="@Val1" Decimals="6" Width="100px" />
<input type="number" @bind-value="@Val1" step="any" style="width: 100px" />
<br />
<b>Val 2:</b>
<input type="number" @bind-value="@Val2" step="any" style="width: 100px" />
<input type="number" @bind-value="@Val2" step="any" style="width: 100px" />
@code {
decimal Val1 { get; set; }
decimal Val2 { get; set; }
protected override void OnInitialized()
{
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("es-ES");
//CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
}
}
[ADMIN EDIT]
In general, our components obey the culture that is set in the application. If the current culture requires a "," decimal separator, our component will accept commas and ignore dots. Our component doesn't know if the user is pressing the decimal separator key on the numeric pad, or the "standard" [ > . ] key.
What we can do to improve the behavior is to implement a feature for automatic handling of the decimal separator character. In other words, if the component detects invalid decimal separator input, it will switch to the correct one. This feature will handle the Numpad key and output it in the right culture.
Here is a possible workaround that uses JavaScript to intercept the "other" decimal separator and insert the "correct" one in the NumericTextBox.
@inject IJSRuntime js
<span @onkeydown="@( (KeyboardEventArgs args) => OnSpanKeyDown(args, "ntb1") )">
<TelerikNumericTextBox @bind-Value="@DValue"
Width="200px"
Id="ntb1" />
</span>
Code: @LogCode , Key: @LogKey
<!-- Move JS to external JS file in production apps -->
<script suppress-error="BL9992">
function addDot(ntbId) {
var textbox = document.querySelector("#" + ntbId);
if (textbox && textbox.value.indexOf(".") == -1) { // or ","
textbox.value += "."; // or ","
}
}
</script>
@code {
decimal DValue { get; set; }
string LogCode { get; set; }
string LogKey { get; set; }
async Task OnSpanKeyDown(KeyboardEventArgs args, string ntbId)
{
LogCode = args.Code;
LogKey = args.Key;
if (args.Key == ",") // or "."
{
await js.InvokeVoidAsync("addDot", ntbId);
}
}
}
Another option in the meantime is to use a standard HTML input or InputNumber with the Telerik CSS class "k-textbox". This way the input will look the same as a Telerik textbox and keep the app look consistent.
Can NumericTextBox Format Be Updatedat run time? In other words, if numerictextbox is being used for dimensions and the user changes the preferred dimensional unit from "centimeters" to "inches" can the Format be changed from "0.## cm" to "0.## in" at runtime?
Same applies if I want to dynamically change the Decimals or Step values. Currently it looks like a dynamic change in the NumericTextBox parameters is not possible.
---
ADMIN EDIT
Here is a workaround that re-initializes the component:
<TelerikButton OnClick="@ChangeFormat">Change format</TelerikButton>
<br />
The value is: @theValue
<br />
@if (isVisible) {
<TelerikNumericTextBox Format="@theFormat" Max="5m" Min="-5m" Step="0.33m" @bind-Value="@theValue"></TelerikNumericTextBox>
}
@code {
private decimal theValue { get; set; } = 1.234m;
string theFormat { get; set; } = "0.## cm";
bool isVisible { get; set; } = true;
async Task ChangeFormat()
{
//workaround
isVisible = false;
await Task.Delay(30);
await InvokeAsync(StateHasChanged);
// change the format
theFormat = "0.## in";
//workaround
isVisible = true;
//await InvokeAsync(StateHasChanged);
}
}
---