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

numericTextBox question

2 Answers 252 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 20 Jun 2012, 01:27 PM
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 () {
  $("#@(Model.DisplayNumber)").kendoNumericTextBox(
      {
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 Answers, 1 is accepted

Sort by
0
Mitch
Top achievements
Rank 1
answered on 28 Jun 2012, 05:22 PM

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? 
0
Dimo
Telerik team
answered on 02 Jul 2012, 08:42 AM
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.

Regards,
Dimo
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
Stephen
Top achievements
Rank 1
Answers by
Mitch
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or