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

How I handle KendoWindow Yes-No click function

2 Answers 471 Views
Window
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Iron
Pierre asked on 24 Oct 2018, 07:16 PM

Hi, I am new with KendoWindow and I got some destroys problem. I use Model KendoWindow to ask confirmation of action on a KendoGrid function. For example, ask for deletion of an item or ask for some item action.

So an button on the command column call a function that ask with modal KendoWindow something than do an AjaxCall to the controller, then reload the grid.

function CalledByTheGridCommandButton() {
    var wndDiv = $("#CopyModalWindows");
        var wnd = wndDiv.kendoWindow({
            title: "Report copy",
            modal: true,
            visible: false,
            resizable: false,
            width: 350
        }).data("kendoWindow");
         
     wndDiv.find("#yes").click(function (e) {
            // Hit YES
            e.preventDefault();
             
            wnd.close();
 
            kendo.ui.progress($("#gridTest"), true);
 
            $.ajax({
                url: "/Admin/Inv_Copy",
                type: "POST",
                data: JSON.stringify({ 'SourceId': selectedItem.FicheInventaireId, 'Annee': $("#AnneeInput").val(), 'Createur': $("#CreateurInput").val() }),
                dataType: "json",
                traditional: true,
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (data.status === "Success") {
                        //Success
                        kendo.ui.progress($("#gridTest"), false);
                        kendoGrid.dataSource.read();
 
                    } else {
                        alert("Error occurs on the Database level!");
                    }
                },
                error: function () {
                    alert("An error has occured!!!");
                }
            });
        });
 
    wndDiv.find("#no").click(function (e) {
                //Hit NO
                e.preventDefault();
                wnd.close();
            });
}

 

But How I can destroy the windows and remove the event on YES and NO button? Do I do it correctly because if I hit several times the command button of the grid I will get multiple YES event attach, then called with unexpected result.

Thanks for your help.

2 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 1
Iron
answered on 24 Oct 2018, 07:54 PM

For now I add this function that I call from my Ajax Callback function or when the user click "NO" on the model windows. 

function CleanModal(domId) {
 
    var wndDiv = $(domId);
 
    wndDiv.find("#yes").off("click");
    wndDiv.find("#no").off("click");
}

In this way I remove the click function on the YES and NO button so when I reopen the modal windows, I do not double the click event and that stop calling the Ajax 2X instead of one.

But I don't know if this is clean enough?

0
Ianko
Telerik team
answered on 26 Oct 2018, 08:45 AM
Hi Pierre,

There is a predefined confirm Dialog widget that does exactly what it is required: https://demos.telerik.com/kendo-ui/dialog/predefined-dialogs. You can check the API reference too: https://docs.telerik.com/kendo-ui/api/javascript/ui/confirm
 
Regards,
Ianko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Window
Asked by
Pierre
Top achievements
Rank 1
Iron
Answers by
Pierre
Top achievements
Rank 1
Iron
Ianko
Telerik team
Share this question
or