Search code examples
office365office-jsoffice-addinsribbonxribbon-control

How to Disable Control type Menu in manifest file in office js add-in


IN this manifest/enabled we can disable a Control type Button.

for example:

      <Control xsi:type="Button" id="BtnOpenTaskpane">
        <Label resid="BtnOpenTaskpane.Label" />
         <Supertip>
         <!-- ToolTip title. resid must point to a ShortString resource. -->
          <Title resid="BtnOpenTaskpane.Label" />
           <!-- ToolTip description. resid must point to a LongString resource. -->
           <Description resid="BtnOpenTaskpane.Tooltip" />
         </Supertip>
         <Icon>
            <bt:Image size="16" resid="Icon.16x16"/>
            <bt:Image size="32" resid="Icon.32x32"/>
            <bt:Image size="80" resid="Icon.80x80"/>
         </Icon>
        <!-- This is what happens when the command is triggered Supported actions are ExecuteFunction-->
        <Action xsi:type="ExecuteFunction">
           <FunctionName>btnopentaskpane</FunctionName>
         </Action>
        <Enabled>false</Enabled> <!--Disable this Control-->
    </Control>

Now I have Control type Menu

for example:

         <Control xsi:type="Menu" id="Contoso.TaskpaneButton2">
                <Label resid="Contoso.TaskpaneButton2.Label" />
            <Supertip>
                <!-- ToolTip title. resid must point to a ShortString resource. -->
               <Title resid="Contoso.TaskpaneButton2.Label" />
                <!--ToolTip description. resid must point to a LongString resource.-->
                    <Description resid="Contoso.TaskpaneButton2.Tooltip" />
                </Supertip>
                <Icon>
                    <bt:Image size="16" resid="heading1-16" />
                    <bt:Image size="32" resid="heading1-32" />
                    <bt:Image size="80" resid="heading1-80" />
                </Icon>
                <Items>
                   <Item id="itemPartTitle">
                     <Label resid="Group2.Item1.Label"/>
                    <Supertip>
                        <Title resid="Group2.Item1.Label" />
                        <Description resid="Group2.Item1.Tooltip" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Contoso.tpicon_16x16" />
                      <bt:Image size="32" resid="Contoso.tpicon_32x32" />
                      <bt:Image size="80" resid="Contoso.tpicon_80x80" />
                    </Icon>
                        <Action xsi:type="ExecuteFunction">
                            <FunctionName>PartTitle</FunctionName>
                        </Action>
                    </Item>
                </Items>
      
               <!--Here We can't Add <Enabled>false</Enabled>-->
            </Control>

I think we can't disable a Control type Menu because it have not Action.

In this case I think we can Disable a Menu Item.

            <Items>
               <Item id="itemPartTitle">
                 <Label resid="Group2.Item1.Label"/>
                <Supertip>
                    <Title resid="Group2.Item1.Label" />
                    <Description resid="Group2.Item1.Tooltip" />
                </Supertip>
                <Icon>
                  <bt:Image size="16" resid="Contoso.tpicon_16x16" />
                  <bt:Image size="32" resid="Contoso.tpicon_32x32" />
                  <bt:Image size="80" resid="Contoso.tpicon_80x80" />
                </Icon>
                    <Action xsi:type="ExecuteFunction">
                        <FunctionName>PartTitle</FunctionName>
                    </Action>
                   <Enabled>false</Enabled>
                </Item>

Here Again a question can we Enable Item

 function enableButton() {
   Office.ribbon.requestUpdate({
     tabs: [
            {
             id: "OfficeAppTab1", 
             groups: [
                 {
                   id: "CustomGroup111",
                   controls: [
                     {
                         id: "MyButton", 
                         enabled: true
                     }
                   ]
                 }
             ]
         }
      ]
  });
}  

In this we have controls to Enable is that work fro Item


Solution

  • Enabling and disabling custom add-in commands (buttons and menu items) dynamically are currently supported, see Enable and Disable Add-in Commands for more information.

    To test for support, your code should call Office.context.requirements.isSetSupported('RibbonApi', '1.1'). If, and only if, that call returns true, your code can call the enable/disable APIs. If the call of isSetSupported returns false, then all custom add-in commands are enabled all of the time. You must design your production add-in, and any in-app instructions, to take account of how it will work when the RibbonApi 1.1 requirement set isn't supported. For more information and examples of using isSetSupported, see Specify Office applications and API requirements, especially Runtime checks for method and requirement set support.