ISSUE: Kendo tooltip with custom angularjs directive and kendoConfirm

317 views Asked by At

My current situation: kendo tooltip works fine alone. my new custom angularjs directive with kendoConfirm works fine alone.

but once i try to use them both together on an element, then only the kendo tooltip stops working.

   <button type="button" title="Disable Item" k-confirm-disable k-confirm-disable-title="'Confirm Disable'" k-confirm-disable-msg="'Are you sure you want to disable this item?'" ng-click="disable(dataItem.id)"  class="btn btn-danger" kendo-tooltip k-content="'Disable Item'" k-options="kendoTooltipOptions">

 $scope.kendoTooltipOptions = {
showAfter: 600,     //time for tooltip appear
position : 'top',
width    : 100
}

kendo tooltip only works when I remove the custom angular directive from the element.

function kConfirmDisable($compile){
return {
    restrict: 'A',
    scope: {
        kConfirmDisableTitle:   '@',
        kConfirmDisableMsg: '@'
    },
    link: function(scope, element, attrs){                      

        var clickHandlers = $._data(element[0]).events.click;

        clickHandlers.reverse(); //reverse the click event handlers list

        var onClick = function(evt) {                        
            evt.preventDefault();
            evt.stopImmediatePropagation();
            if(!scope.kConfirmDisableTitle) {
                scope.kConfirmDisableTitle = "Confirm";
            }

            if(!scope.kConfirmDisableMsg) {
                scope.kConfirmDisableMsg = "Are you sure?";
            }

            angular.element("<div></div>").kendoConfirm({
                title: scope.kConfirmDisableTitle.replace(/['"]+/g, ''),
                content: scope.kConfirmDisableMsg.replace(/['"]+/g, ''),
                buttonLayout: "normal",
                visible: false,
                actions: [
                     {
                        text: "No",
                        Primary: false,
                        action: function(){

                            evt.preventDefault();
                            evt.stopImmediatePropagation();                                
                        }
                    },
                    {
                        text: "Yes", 
                        Primary: true,
                        action: function(){                               

                            element.unbind(this);
                            setTimeout(function() {
                                element.unbind("click", onClick);
                                element.click();
                                evt.preventDefault();
                                evt.stopImmediatePropagation();
                                element.on("click", onClick);
                            },0);
                        }
                    },

                ],
                animation: {
                    open:{
                        effects: "zoom:in",
                        duration: 250
                    },
                    close:{
                        effects: "fade:out",
                        duration: 250
                    }
                },
                open: function(e) {
                   $("html, body").css("overflow", "hidden");
                },
                close: function() {
                    $("html, body").css("overflow", "visible");
                }
            }).data("kendoConfirm").open().result;
        };
        element.on("click", onClick);

        clickHandlers.reverse();
    }
}
}
2

There are 2 answers

0
mindtaker On BEST ANSWER

my solution is I removed the "k-" from the "k-confirm-disable" directive and it worked. i think its because kendo has "k-" reserved.

0
elpddev On

Since Kendo AngularJs source is not available, I can only suggest couple of things:

  1. Try to research what happens if you dont stop the propagation and not stop the default on the click in your directive. If the scenario is that it does not work immediately on page reload and hovering on the element without using clicks- then this is not relevant.

  2. Avoid using isolated scope in your directive and get the attributes via the $attrs link function parameter. Since you did not specify you get js error, I am assuming Kendo isn't using isolated scope, but it is still a direction to investigate.