Legion
Legion

Reputation: 3437

Changing kendo textbox value loses formatting

I have a basic textbox defined as:

@Html.Kendo().TextBoxFor(m => m.myNumber).Format("{0:#,###}").HtmlAttributes(new { @readonly = "readonly", style = "width:150px;" })

After doing an ajax call I update the value via javascript:

$("#myNumber").val(data.myNumber);

However now the formatting is lost, there's no longer a comma thousands separator present. Is there a javascript function I need to call on $("#myNumber"), like a rebind or refresh? For some reason telerik doesn't have any documentation for their textbox.

Upvotes: 0

Views: 1033

Answers (1)

Drew B.
Drew B.

Reputation: 1145

Copying answer from the comments:

I think what you're more looking for is the NumericTextBox. This will give you the proper controls of being able to set it's format and then in the javascript after your ajax call, set the value of the kendo object to maintain formatting. Right now all you're doing is selecting a plain jQuery html element and setting it's value. That won't interface with the kendo textbox (which isn't an object) at all. You'll either need to return your value in the format you desire or explore @Kevin's option as alternatives.

Upvotes: 2

Related Questions