Search code examples
javascriptjquerykendo-gridjquery-ui-datepickerkendo-datepicker

Close Event in Kendo Datepicker fire many times


I have created a template in my grid:

template: '#if(IniReal != ""){# <div class="text-center">#= IniReal #</div> # } else {#<input class="fechaReal" />  #} #',

in this template a datepicker is created when the element of my arrangement comes empty

$(".fechaReal").kendoDatePicker({
                            format: "dd-MM-yyyy",                            
                            parseFormats: ["dd-MM-yyyy"],
                            change: vmSeg.Cambio,
                            close: vmSeg.Cerrar
                        });

the problem lies in the Close event after firing for the first time, the next time it fires, it does it twice, and so on, I just want the Close event triggered once and it does not fire repeatedly

This is my event Close

 vmSeg.Cerrar = function (e) {
                $("#ActiSeguimiento").on("focusout", ".k-datepicker", function (e) {
                    vmSeg.grid = $("#ActiSeguimiento").data("kendoGrid");
                    vmSeg.dataItem = vmSeg.grid.dataItem($(this).closest("tr"));                    
                    vmSeg.dataItem.IniReal = vmSeg.NuevaFecha;
                    return false;
                });
            }

and this is my event Change:

vmSeg.Cambio = function(e) {
                vmSeg.NuevaFecha = kendo.toString(kendo.parseDate(this.value()), "dd-MM-yyyy");

            }

What is wrong in my event Close?


Solution

  • I have inspected the dojo that you provided and it seems like the issue is caused by declaration of the 'focusout' event that is hooked on every close not in the Kendo widget. When I removed the decalration of the 'focusout' event the scenario worked correctly. The close was triggered correctly at my side yet the 'focusout' was triggered many times. In such case I would recommend you to define as here it separately so that it triggers only once.