numericTextBox question

3 posts, 0 answers
  1. Stephen
    Stephen avatar
    5 posts
    Member since:
    Mar 2012

    Posted 20 Jun 2012 Link to this post

    I'm attempting to add a min and max for an integer style numericTextBox using Razor etc
    I can see the values getting set to the correct values using console.debug, but the widget does not respect those limits.
    I also tried having an onLoad function to set the min and max but that does the same thing..    
    Any ideas on this one ?

    <input type="text" id="@(Model.DisplayNumber)" name='answer' value='@answerValue' class="number-only" />

    <script type="text/javascript">
        $(document).ready(function () {    
        var numericTextBox = $("#@(Model.DisplayNumber)").kendoNumericTextBox({
          format: "#",
          decimals: 0
        if (@Model.RangeMin != null)
           numericTextBox.min = @Model.RangeMin; 
        if (@Model.RangeMax != null)
           numericTextBox.min = @Model.RangeMax; 

    Should have mentioned, this works fine but doesn't check whether the min and max have any values..

    $(document).ready(function () {
    min: @Model.RangeMin, max: @Model.RangeMax, format: "#", decimals: 0})

    Ok I'll try a different question. When an object is retrieved back from the Datastore, you cannot change it ?
    In other words the "numericTextBox" cannot be altered by .min= etc.. Or, do I have to save it back,  Or I need to set the min and max in a different way. 

    Please let me know if I'm wasting more time and this just isn't possible yet, Or if it's coming and when it does it will be done a different way... anyone out there ?

  2. Mitch
    Mitch avatar
    1 posts
    Member since:
    Jun 2012

    Posted 28 Jun 2012 Link to this post

    I ran into this same issue – setting the min/max values after initialization – and I found a solution.

    The problem with setting options after initialization, as shown above, is that the options (format, min, max, etc) aren’t stored as properties of the kendoNumericTextBox object.  So assigning like this…

        numericTextBox.min = @Model.RangeMin;

    …isn’t really setting the minimum as intended, instead it’s adding a new property to the object, which is ignored by the kendo logic.

    What I found, is that the options are stored as properties of a property called ‘options’, and there is also a method named ‘setOptions’ for merging options and event bindings.  So I was able to set the options using these two approaches:

        numericTextBox.options.max = @Model.RangeMax;
        numericTextBox.setOptions({ max: @Model.RangeMax });

    (We're using Kendo version 2012.1.322.)

    I have two follow-up questions for Kendo –

    1. For simple changes, for example, just setting one option – do you recommend one approach over the other?
    2. It’s a little surprising to me that these are not in the documentation online – is there are reason?  Are these going to be added to the documentation in the future?  Are they being deprecated? 
  3. Dimo
    Dimo avatar
    8482 posts

    Posted 02 Jul 2012 Link to this post

    Hello Mitch,

    It doesn't matter which of the two techniques you are using. setOptions is more convenient for applying several settings at once.

    The setOptions method is not part of the public API and it is also a method of the Widget type, not of a specific Kendo UI widget. In addition, applying options after widget initialization may not take effect in all scenarios, depending on the specific option and widget. That's why setOptions is not included in the documentation.

    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top