8

I want to add new button to the ribbon in Pages library. To do so, I have following code:

<CustomAction Id="Ribbon.PublishTab.Publishing.Actions.UploadDocumentButton" Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.EditingTools.CPInsert.Links.Controls._children" >
          <Button Id="Ribbon.PublishTab.Publishing.UploadDocumentButton1" Command="Test1"
                  Image16by16="/_layouts/15/Solution/Images/Al_16_by_16.jpg"
                  Image32by32="/_layouts/15/Solution/Images/Al_32_by_32.jpg"
                  LabelText="Upload File" TemplateAlias="o1" Sequence="100" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Test1" CommandAction="javascript:function Action()
                          {
                            alert('hello');
                          } 
                          Action();"  EnabledScript="javascript:function JustReturnTrue(){  return true;}JustReturnTrue();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

The ribbon button appears on proper place. But it is always disabled. After try things, I figured out that when I remove command attribute from <Button> tag it is getting enabled but when I place the same attribute and deploy, it is getting disabled.

What am I missing?

4
  • I think this because of missing semicolon in after return true statement in JustReturnTrue() method. Commented Jan 27, 2015 at 11:46
  • Hello Sir, I added the semicolon(;) after return true (as per my updated question) but getting the same issue. @NadeemYousuf
    – users1100
    Commented Jan 27, 2015 at 12:26
  • please try to use developer tools (using f12 regardless of your browser) and check for any javascript errors. Code seems legit. Commented Jan 27, 2015 at 13:36
  • Did you ever find a solution to this? I am having a similar problem where the button is always disabled. However, I want it always enabled, so I am not using EnabledScript at all. Commented Mar 4, 2016 at 20:38

2 Answers 2

0

If your button is enabled in all conditions, try to remove the EnabledScript property.

2
  • Removed the attribute for enabling the option but not working yet.
    – users1100
    Commented Jan 27, 2015 at 12:54
  • 1
    Try this : <CommandUIHandler Command="Test1" CommandAction="javascript:alert('Hello, world');"/>
    – KhalilG
    Commented Jan 27, 2015 at 14:42
0

I had a similar Problem and discovered that removing the space before the commandUIHandler closing tag helped.

So instead of

return true;}JustReturnTrue();" />

do this:

return true;}JustReturnTrue();"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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