# Custom MenuItem

## What is Custom MenuItem?

Widget's right click menu support add custom menuitem. you can create "menu" node in "widget.json" file to create custom menuitem. Custom MenuItem can bind measure to send command to measure or run javascript code.&#x20;

Measures are also can auto create custom menuitem by default. if you do not need custom menuitem by measure ,just add this code in measure section  `"autoCreateCustomMenu" : false`   &#x20;

## Sample

```javascript
  "menu":[
    {
      "caption":"Update Weather",
      "measure":"weather1",
      "onClick":"update"
    },
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }
  ]
```

## How to Create MenuItem&#x20;

Found the "menu" json node in file "widget.json",if not, you need create a json node named "menu"\
for excample :

```javascript
{
  "information":{
    "author":"",
    "width":300,
    "height":300,
    "name":"Simple Weather"
  },
  "measure":{
    "weather":{
      "name":"weather1",
      "title":"Weather",
    }
  },
  "menu":[

  ]
}
```

Add MenuItems into the menu json node like this:

```
  "menu":[
    {
      "caption":"Update Weather",
      "measure":"weather1",
      "onClick":"update"
    },
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }

  ]
```

### MenuItem Property

**caption** : MenuItem title

**measure**: the measure name of bind

**onClick**: when the menuitem clicked,the command of the bind measure will be invoked

**isChecked** : the menuitem will be checked when the value is true

**enabled**: the menuitem will be gray and can not click when the value is false

## How to Display Measure Setting Window by MenuItem

Measure setting menuitem is auto created by default, you can disable it by "autoCreateCustomMenu".

```javascript
"measures":{
  "shortcut":{
    "name":"shortcut1",
    "autoCreateCustomMenu" : false,  //disable auto create menuitem for measure
    "autoCreateSettingTab" : false,  //disable auto create setting tab for measure
  }
}
```

You also can create measure menuitem by set the menuitem measure field with the measure name , and set the onClick field with "setting",for excample:

```
  "menu":[
    {
      "caption":"Change Location",
      "measure":"weather1",
      "onClick":"setting"
    }
  ]
```

{% hint style="info" %}
You can found all the measure command from [here](/rainwidget/reference/measures.md#datasource-common-command)
{% endhint %}

## How to Run JavaScript Code&#x20;

You can run javascript code when the menuitem was clicked by set the measure to blank and set the js code into the onClick property. It can execute multiple js statements at the same time.

```
"menu":[
  {
    "caption": "do some thing",
    "onClick" : " cmd('weather1','update');  cmd('showMsg','Weather Update Start!'); "
  }
]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rainysoft.gitbook.io/rainwidget/reference/custom-menuitem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
