Search code examples
kendo-uikendo-templatekendo-datepicker

Datepicker control is not displayed correctly inside of kendo ui template


I have a kendo ui template with a datepicker control

<script type="text/x-kendo-template" id="tmplStep1">     
 <form>
    Date: <input id="datepicker" maxlength="10"/>  
    <i>(mm/dd/yyyy)</i><br />  
 </form>  
</script>

I'm using a Windows Popup to display the template in this way

var detailsTemplate = kendo.template($("#tmplStep1").html());
dataItem = this.dataItem(e);
var wnd = $("#winDate")
           .kendoWindow({
                 title: "Form",
                  modal: true,
                  visible: false,
                  resizable: false,
                  width: 100,
                  appendTo: "form#frm"                     
              }).data("kendoWindow");

         wnd.content(detailsTemplate(dataItem));            
         wnd.center().open();

I know, I need to initialize the datepicker, but I don't know how to do it. I put the below instruction outside of the template, but obviously it is not working, the control displayed is a simple textbox.

<script>
      $("#datepicker").kendoDatePicker();
</script>

Does anyone know how to resolve it?


Solution

  • call $("#datepicker").kendoDatePicker(); right after you set template as window content, because before that temlate is not a part of DOM yet:

    ...
    wnd.content(detailsTemplate(dataItem));
    $("#datepicker").kendoDatePicker();
    wnd.center().open();