NumericTextBox with custom display for zero

1 Answer 29 Views
NumericTextBox
Travis
Top achievements
Rank 1
Travis asked on 19 Nov 2024, 07:48 PM

I am attempting to change my existing NumericTextBox to do something custom when the value is zero. It was requested that we display a double zero in that one scenario. All other scenarios should act the same as they do out of the box for the NumericTextBox. Is this do-able with the existing functionality of the NumericTextBox?

Basically the request is to do this --

Value: 0

Display: 00

 

Value: 234

Display 234

1 Answer, 1 is accepted

Sort by
1
Accepted
Nikolay
Telerik team
answered on 22 Nov 2024, 10:19 AM

Hi Travis,

This functionality is not coming out of the box. However, you can use the setOptions() method to update the format conditionally in the change NumericTextBox event handler. For example:

$("#numerictextbox").kendoNumericTextBox({
        format: "0",
        change: function(e) {
          if(e.sender.value() === 0) {
            e.sender.setOptions({
              format: "0.0"
            })
          } else {
            if(e.sender.options.format == "0.0") {
              e.sender.setOptions({
                format: "0"
              })
            }
          }
        }
      });

Dojo demo: https://dojo.telerik.com/NqTqqWqH

Regards,
Nikolay
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.

Travis
Top achievements
Rank 1
commented on 22 Nov 2024, 04:04 PM

Thanks for this
Tags
NumericTextBox
Asked by
Travis
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or