Pankaj Vanjara
Pankaj Vanjara

Reputation: 21

Can we disabled menu items from contextual ribbons?

In my project I am generating ribbons dynamically using Office.riboon method. But, Issue is that I am not able to disabled the menu items only controls are enabled and disabled.

So, Is there any way to enabled or disabled the menu items using Office ribbon APIs?

Need to hide menu item that mentioned in below image

Ribbon API for generating contextual ribbons dynamically

Upvotes: 0

Views: 71

Answers (1)

Rick Kirkham
Rick Kirkham

Reputation: 9784

Yes. The dynamic ribbon schema provides an "enabled" property for menuItems: Here are the relevant excerpts. Note that menuItemElement inherits the property from actionableElement.

"actionableElement": {
        "$comment": "An abstract type represents controls which can trigger an action.",
        "allOf": [
            {
                "$ref": "#/definitions/buttonLikeElement"
            },
            {
                "properties": {
                    "enabled": {
                        "title": "Title",
                        "description": "Specifies whether the control is enabled when the ribbon is generated.",
                        "type": "boolean",
                        "default": true
                    },
                    "actionId": {
                        "title": "Action ID",
                        "description": "The action to perform.",
                        "type": "string"
                    }
                },
                "required": [
                    "actionId"
                ]
            }
        ],
        "additionalProperties": false
    },
...
 "menuItemElement": {
        "title": "Menu Item Element",
        "description": "A menu item element in a menu.",
        "allOf": [
            {
                "$ref": "#/definitions/actionableElement"
            },
            {
                "properties": {
                    "type": {
                        "title": "Type",
                        "description": "Type of the element.",
                        "const": "MenuItem"
                    }
                },
                "required": [
                    "type"
                ]
            }
        ],
        "additionalProperties": false
    },

The whole schema is at: dynamic-ribbon-schema.

You can set the "enabled" property using the Office.ribbon.requestUpdate() method. Examples are at: Enable and disable Add-in Commands.

Upvotes: 1

Related Questions