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

Need empty value when using NumericTextBoxFor(...)

1 Answer 1260 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
BigzampanoXXl
Top achievements
Rank 1
BigzampanoXXl asked on 10 Jan 2013, 11:05 AM
Hi,

first of all, this is how I implemented the NumericTextBox, bound to an integer:
@(Html.Kendo().NumericTextBoxFor(m => m.Number)
.Name("ntb")
.Format("n0")
.Min(1)
.Max(50)
)

My problem is:
As soon as I bind something against the NumericTextBox (when I use NumericTextBoxFor(...)), the value is never empty. It looks empty but as soon as the user clicks inside the TextBox the value of the bound integer (int.MinValue or whatever value the property has) is shown. First of all - the value (int.MinValue) makes no sense because the Min-property is set to 1. Secondly, why is there anything? The NumericTextBox should be empty, because I didn't set a value.

This problem causes, that the user has to delete the value first before he is able to insert something. On initialisation of the NumericTextBox it should be empty - but it should also be bound to a property.

Is there any workaround or solution for this problem? Hope someone can help me.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 14 Jan 2013, 08:27 AM
Hello,

This behavior is expected and is by design. The value is automatically populated from the model when the NumericTextBoxFor helper is used or the name is the same as the name of a property from the model. The same behavior can be observed for any HTML helper. If you wish to avoid this, I can suggest to use the NumericTextBox helper instead and set the input name through the HtmlAttributes method e.g.

@(Html.Kendo().NumericTextBox()
    .Name("ntb")
    .HtmlAttributes(new { name = "Number" })
    .Format("n0")
    .Min(1)
    .Max(50)
)
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
NumericTextBox
Asked by
BigzampanoXXl
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or