6

I am deploying custom ribbon button using SharePoint provider hosted app. I was able to show button where I wanted but not able to control enable or disable state of the button. It remains active regardless of list item selected or not.

Here is custom control xml for the ribbon button,

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="33080663-4c4a-457f-aae5-d2185039bdb5.RibbonCustomAction_ConvertPDF"
                RegistrationType="ContentType"
                RegistrationId="0x0101"
                Location="CommandUI.Ribbon"
                Sequence="10001"
                Title="Convert to PDF">
    <CommandUIExtension>
      <!-- 
      Update the UI definitions below with the controls and the command actions
      that you want to enable for the custom action.
      -->
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Copies.Controls._children">
          <Button Id="Ribbon.Documents.Copies.RibbonCustomAction_ConvertPDFButton"
                  Alt="Convert to PDF"
                  Sequence="11"
                  Command="Invoke_RibbonCustomAction_ConvertPDFButtonRequest"
                  LabelText="Convert to PDF"
                  TemplateAlias="o1" CommandType="OptionSelection"
                  Image32by32="~SiteCollection/SiteAssets/Muhimbi/pdf32.gif"
                  Image16by16="~SiteCollection/SiteAssets/Muhimbi/pdf16.gif" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Invoke_RibbonCustomAction_ConvertPDFButtonRequest"
                          CommandAction="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}&amp;Action=listpdf&amp;SPListItemId={SelectedItemId}&amp;SPListId={SelectedListId}&amp;Source={Source}"
                          EnabledScript="javascript:function multiEnable() {  var items = SP.ListOperation.Selection.getSelectedItems(); return (items.length > 0); } multiEnable();" />
      </CommandUIHandlers>
    </CommandUIExtension >
  </CustomAction>
</Elements>

In on-premise deployment, we handle "EnabledScript" event to control enable/disable state of the button. I have done exactly what I used to do before but it's not working. I have also tried to put just alert('') to check if the event is firing but looks like "EnabledScript" event is not firing at all.

  • I was looking for this solution a few weeks ago, and I found a post somewhere that Microsoft disabled this in SharePoint Online (I'm in SPO as well). I will try to find the link and post it. – wjervis Dec 18 '14 at 13:51
0

According to MSDN (search for CustomAction on page) you are not allowed to put Javascript in a CommandAction, only URLs are expected there.

But as it turned out you still can add custom action with JavaScript in CommandAction and with EnabledScript attribute using JSOM or SSOM. Check this example, it works for me.

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.