Set Options for Multiple DatePickers using setOptions

6 posts, 1 answers
  1. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 27 Nov 2014 Link to this post

    Considering the following HTML: 
    <input value="" class="date-depth-year"><br />
    <input value="" class="date-depth-year"><br />
    <input value="" class="date-depth-year"><br />
    <input value="" class="date-depth-year"><br />
    <input value="" class="date-depth-year"><br />

    Why does the following NOT work (to be specific, it sets the min date for the first date picker only, not all of them): 

    <script>
        $(".date-depth-year").kendoDatePicker({
          start: "year",
          depth: "year"});
         
        console.log ($("[data-role=datepicker]").length);
        $("[data-role=datepicker]").data("kendoDatePicker").setOptions({
          min: "2014/12/01"
        });
         
      </script>

    I know I can do this using a jQuery each loop, which definitely works, but I was interested to know why the above JS wouldn't work to set the min values for all the DatePickers on that page? 

    See the following dojo:
    http://dojo.telerik.com/@Jacques.vanderhoven/ebawO

    Thanks,
    Jacques
  2. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 27 Nov 2014 Link to this post

    Hello Jacques,

    Currently Kendo UI will not loop[ through the items passed to the initialization script. And this is why we recommend the use of ID's in order to render the widgets on the page with unique identifiers. 

    The workaround you already know - loop through the selection and initialize every single widget. it should not make much difference from a performance standpoint.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 27 Nov 2014 in reply to Kiril Nikolov Link to this post

    Hi Kiril, 

    I think you might have that wrong. 

    You CAN initialize all widgets like that with a single call, you just can't do something like setOptions after the widget has been initialized already.

    ?
  5. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 27 Nov 2014 Link to this post

    Hello Jacques,

    Well it will work in some cases. The reason is the same - Kendo UI will not loop through the selected items and execute the function for each one of them and will set the first widget only.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 27 Nov 2014 in reply to Kiril Nikolov Link to this post

    Not sure this makes much sense, but ok I'll accept that. I've marked your previous comment as the answer. 

    Thanks,
    Jacques
  7. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 28 Nov 2014 Link to this post

    Hello Jacques,


    Happy to hear that you accepted the answer.

    In case you have any other questions, do not hesitate to contact us.

    Regards,

    Kiril Nikolov

    Telerik

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

     

Back to Top
Kendo UI is VS 2017 Ready