This is a migrated thread and some comments may be shown as answers.

Can't reset value of NumericTextBox

4 Answers 3258 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 31 Jul 2012, 06:45 PM
I can set the value to a specific amount like this:
$("#ntAmount").data("kendoNumericTextBox").value(100);
But if I try this after setting the value as above, the value does not change.
("#ntAmount").data("kendoNumericTextBox").value("");
I have also tried the following with nothing being able to clear out the previously set value.
("#ntAmount").data("kendoNumericTextBox").value(0); 
("#ntAmount").data("kendoNumericTextBox").value(null); 

Is there any way to clear out the value once it's been set?

4 Answers, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 09 Aug 2012, 07:03 PM
Hi Bryan,

There are several things that need to happen to clear the value.  If I have a NumericTextBox defined as follows:

var _numeric = $("#numeric").kendoNumericTextBox({
    min: 0,
    max: 100
}).data("kendoNumericTextBox");
 
I could clear it with the following lines of code:
 
_numeric._old = _numeric._value;
_numeric._value = null;
_numeric._text.val(_numeric._value);
_numeric.element.val(_numeric._value);

Another possibility is if you want to use this for any of your NumericTextBox controls, you could extend the NumericTextBox.  This would be done after the reference to the kendo javascript library, but before any NumericTextBox's are created.  Here would be the code:

$.extend(window.kendo.ui.NumericTextBox.fn, {
    clear: function() {
        this._old = this._value;
        this._value = null;
        this._text.val(this._value);
        this.element.val(this._value);
    }
});

Then, to clear a NumericTextBox, you could call the clear function like this:

_numeric.clear();

Attached is an example of this.

Regards,

John DeVight
0
Jack
Top achievements
Rank 1
answered on 11 Jan 2016, 08:53 PM
Thank you Mr. DeVight.  You helped me out a lot.  Works great.
0
Allan
Top achievements
Rank 1
answered on 04 Oct 2017, 01:54 AM
Whilst this does indeed clear the textual value, the tooltip remains when you hover over the "cleared" input field.  Is there a way to also clear that, or better yet, Telerik, what is correct way to reset the numeric textbox back to empty?
0
Tsvetina
Telerik team
answered on 06 Oct 2017, 04:16 PM
Hello Allan,

You can set the NumericTextBox value to null to clear the textbox and tooltip:
var numeric = $("#currency").data("kendoNumericTextBox");
numeric.value(null);

Dojo: http://dojo.telerik.com/@tsveti/Acepoz

Regards,
Tsvetina
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
NumericTextBox
Asked by
Bryan
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Jack
Top achievements
Rank 1
Allan
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or