0

I have added a custom action "Test Link" to item_CommonHoverPanel_Actions display template as shown in figure below:

enter image description here

Every thing works fine if i hover over Test 1 and Click on "Test link". But if i just hover over Test 1 (Without clicking on "Test link)" and then hover over test 2 and click the "Test Link", it doesn't work. Following is the code snippet:

 AddPostRenderCallback(ctx, function() { 
                if(typeof jQuery === 'undefined') {
                        EnsureScriptFunc('jquery.min.js', null, function() {
                            jQuery(".TestLink").on("click",function(e) {
                                 e.preventDefault();                             
                               alert('clicked');                               
                            });                     
                        });
                }
                else{
                    console.log('Jquery Loaded loaded');
                }               
        }); 

I think the click event got attached to the hover panel that appears first on the page. Does any one have this problem before and know how to solve it?

  • The hover is only loaded once, if you hover a second time no additional hover code is run. You need to ensure that your click code and the binding is associated with the appropriate event considering this timing. – Matthew McDermott Nov 26 '15 at 13:17
0

Got help from one of my colleague, but here is how we solve it.

 AddPostRenderCallback(ctx, function() {        
            if(typeof jQuery === 'undefined') {
                    EnsureScriptFunc('jquery.min.js', null, function() {
                        jQuery("#yourtestid" + ctx.CurrentItem.ListItemID).on("click",function(e) {
                            alert(ctx.CurrentItem.ListItemID);
                        });                     
                    });                 
            }
            else{
            jQuery("#yourtestid" + ctx.CurrentItem.ListItemID).on("click",function(e) {

                        e.preventDefault();
                        console.log(ctx.CurrentItem.ListItemID);                            
                        alert(ctx.CurrentItem.ListItemID);                                                      

                });
            }               
    }); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.