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

[Solved] IntegerTextBoxFor: value displayed upon resetForm() vs. focus

3 Answers 131 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Luke
Top achievements
Rank 1
Luke asked on 08 Jun 2011, 08:23 PM
Hello,

I am currently using an IntegerTextBoxFor in a form. The form has a cancel button which calls resetForm() (actually, it calls a jquery function which calls resetForm(), amongst other things). Upon changing the value in the IntegerTextBox, the cancel button becomes enabled. Pressing the cancel button should reset the value of the IntegerTextBox.

Observed behaviour: Pressing cancel does not change the value displayed in the IntegerTextBox (values in other fields of the form are reset immediately). However, the next time focus is set on the IntegerTextBox, the correct (reset) value is displayed.

Is there a way to make the IntegerTextBoxFor update right away, when the cancel button is pressed?
Thanks for any help!
Luke

Here's the code that I imagine would be relevant:
In the View:
@(Html.Telerik().IntegerTextBoxFor(m => m.Port)
    .EmptyMessage(Html.Stm(Language.MessageValueNotSet))
    .NumberGroupSeparator("")
    .HtmlAttributes(new { onkeyup = "EnableButtons()" }))
...
<button type="reset" onclick="ResetForm()">@Html.Stm(Language.ButtonCancel)</button>


The jquery function:
// Resets the form
function ResetForm() { 
    $('form').validate().resetForm(); 
    $(":input").hideErrorLabel(); 
    DisableButtons();
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 09 Jun 2011, 01:26 PM
Hi Luke,

I am glad to inform you that we have fixed this bug and changes will take effect in the next internal and official builds.

I have updated your Telerik points for bringing the issue to our attention. Thank you.

Best wishes,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Landon
Top achievements
Rank 2
answered on 07 Oct 2011, 09:02 PM
Hi Dimo,

My apologies for re-surfacing this thread, but I am also getting this same error and unfortunately my code isn't stable enough at the moment to risk an upgrade. Is there any possible work-around for this bug?

Best Regards,
Landon

EDIT:

For anyone else experiencing this problem and is not in a position to upgrade your MVC, I've found a workaround for the solution using the Telerik API:

var textBox = $('#NumericTextBox01').data('tTextBox');
textBox.value(0);

This works the same as if you were to set a regular input box's text() or val().
0
Dimo
Telerik team
answered on 10 Oct 2011, 08:43 AM
Hello Landon,

A workaround for people using older versions of our MVC components is to subscribe to the form reset event and set the NumericTextBox value via the API by using the value in the <input> element.

// inside form reset handler
window.setTimeout(function () {
      var ntb = $("#NumericTextBoxID").data("tTextBox);
      ntb._value(ntb.$element.val());
}, 1);

This is what the newer versions of the NumericTextBox do internally.

Regards,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
NumericTextBox
Asked by
Luke
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Landon
Top achievements
Rank 2
Share this question
or