Question

Is it possible to add some kind of JavaScript validation to ECB items like Edit Item, Check Out and Workflows? What I want is a simple JavaScript alert and redirect to the list if the clicked item does not pass the validation, on the other hand the user will be redirected to the specific page if the item passed the validation (ie Workflow.aspx if the user clicked on Workflows). Overriding functions like AddCheckinCheckoutMenuItem from core.js in an content editor webpart didn't work for me (is it even possible?). I also dont't want to create a whole new ECB, that's why I don't want to use Custom_AddDocLibMenuItems and return false.

What I want in pseudo-code in the ECB onclick for non-custom items:
if(condition) JS alert; redirect back to list; else normal behavior;

Was it helpful?

Solution

I've done this before, and worked for me. There are several functions that govern the ECB menu and that you can override (where "can" means you have the ability to do that because this is javascript, but obviously this is not something officially supported, meaning that a future SharePoint update or service pack might break your code).

They are:

AddDocLibMenuItems //(the main function that shows all the ECB actions by calling the other functions listed below)
CAMOpt //(creates all the menu items)    
AddSharedNamespaceMenuItems //(show View/Edit)
AddSendSubMenu //(send to)   
AddDocTransformSubMenu //(convert document)    
AddWorkflowsMenuItem //(create the workflow menu item)
CIMOpt //(custom actions)

Here's an example of an overridden CAMOpt function that shows an alert when the Workflows menu item is clicked:

CAMOpt = function (p,wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
{ULSsa6:;
if (wzText == "Workflows") wzAct = "alert('hi there!')";    
var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc);
    if(!mo)return null;
    AChld(p,mo);
    return mo;
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top