omid
omid

Reputation: 71

how can i clear the value of the kendo numeric textbox?

I have done this and it's not working

$("#txtLowValue").val('');
$("#txtLowValue").val();

and this is the text box

$('#txtLowValue').kendoNumericTextBox({
    format: "##",
    decimals: 0,
    spinners: false,
    min: 0,
    max: 999998
});

Upvotes: 5

Views: 11683

Answers (2)

Allan Nielsen
Allan Nielsen

Reputation: 270

I found this on the telerik forums: http://www.telerik.com/forums/can-t-reset-value-of-numerictextbox

Exert from the above link: 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();

Upvotes: 0

David Shorthose
David Shorthose

Reputation: 4497

Here is a simple example for you to test.

http://dojo.telerik.com/IQaSE

The important bit is this:

$('#txtLowValue').data("kendoNumericTextBox").value(null);

here is a link to the api documentation: value

Upvotes: 9

Related Questions