Need empty value when using NumericTextBoxFor(...)

2 posts, 0 answers
  1. BigzampanoXXl
    BigzampanoXXl avatar
    60 posts
    Member since:
    Jan 2007

    Posted 10 Jan 2013 Link to this post

    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.
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 14 Jan 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top