Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Obviously, this is something I need to do just in certain circumstances (determined by the current contents of a list).

The reason I want to keep the action visible is to set its description to say something like "Once you add new items, this action will be active again".

Thanks in advance Josh

share|improve this question
    
It will probably depend on where your custom action is going to land and on what version of the product (2007 or 2010). For instance, as GillouX stated, you can enable/disable Ribbons as such. For items somewhere else, i.e. Site Settings page, it will be different. –  MBSurf Jun 23 '11 at 18:03
    
Since MenuItemTemplate is in the Microsoft.SharePoint.WebControls namespace, and at first glance looks like a web control, I was hoping to find a .Enabled attribute. But no such luck. –  Josh Korn Jun 23 '11 at 21:36
add comment

3 Answers

It's far from the most elegant thing I've done, but it'll work for now.

The seed of the idea comes from this blog entry.

To make it work, I used a Content Editor webpart containing this jQuery snippet:

<script type="text/javascript">

$(document).ready(function(index){ 
   $("[text*='My Custom Action Text']").each(function() {
      $(this).attr('disabled', true);
      $(this).attr('onmenuclick', '');
   })
});

</script> 

In an IE-exclusive environment, the .disabled setting is sufficient to do exactly what's required. But it looks like the .disabled attribute isn't in the Firefox object model, so if it's necessary to make it function in the Firefox world, you also need the .onmenuclick line.

Firefox still doesn't grey out the item, but it renders the action null.

share|improve this answer
add comment

if you speak about a button in the Ribbon, the only way to enable/disable the button based on some rules is to defined in your CommandUIHandler the EnabledScript properties.

 <CommandUIHandlers>
     <CommandUIHandler
      Command="MyCommand"
      CommandAction="javascript:ProcessItems();"
      EnabledScript="javascript:EnableButton();"/>
 </CommandUIHandlers>
share|improve this answer
    
Ribbon? Not really 8-) We're talking a MOSS2007 Action item, I'm afraid. –  Josh Korn Jun 23 '11 at 17:27
    
you didn't specify it, my guess is that you are riding SP2010 :D –  GillouX Jun 23 '11 at 19:12
add comment

I would look at a couple of features that enabled / disabled your actions based on required criteria.

This link may be useful:

http://blogit.create.pt/blogs/andrevala/archive/2008/08/11/SharePoint-2007-Deployment_3A00_-Custom-Action-Features.aspx

share|improve this answer
    
Won't work, unfortunately. The state of the list changes on the fly, so I guess I need to change the state of the MenuItemTemplate on the fly also. –  Josh Korn Jun 23 '11 at 21:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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