NumericTextBox: Prevent clearing of values when a pasted value contains letters etc.?

1 Answer 63 Views
NumericTextBox
Wesley
Top achievements
Rank 1
Iron
Wesley asked on 20 Jun 2022, 09:29 AM | edited on 04 Jul 2022, 09:44 AM

When pasting a value that contains letters and numbers, the Native NumericTextBox removes the letters but then clears the entire value when you defocus the input. In this Stackblitz project you can see this behavior. The problem occurs with or without decimals or different formats.

Proposed solution
When the NumicTextBox removes the letters keep the value on defocus when it only contains numbers.

Steps to reproduce

  1. Paste the value abc123
  2. See that the letters in the input are removed after pasting.
  3. See that the entire value is cleared when you defocus the input.

1 Answer, 1 is accepted

Sort by
2
Accepted
Petar
Telerik team
answered on 20 Jun 2022, 10:13 AM

Hi, Wesley.

Check this StackBlitz example. It demonstrates the functionality that you need to implement in your application. To achieve the demonstrated behavior, we are using the following methods:

updateValue(e) {
  this.value = this.pastedValue;
},
onInput(e) {
  this.pastedValue = Number(e.target._value);
}

The first one is triggered when the change or blur event of the NumericTextbox is triggered. The onInput method is triggered when the input event is triggered. 

Let me know if you have questions about the suggested approach.

Regards,
Petar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
NumericTextBox
Asked by
Wesley
Top achievements
Rank 1
Iron
Answers by
Petar
Telerik team
Share this question
or