# How to add action for button in plugin

**URL:** <https://meta.discourse.org/t/how-to-add-action-for-button-in-plugin/153383>\
**Category:** Development\
**Created:** [May 31, 2020, 1:09pm UTC](https://meta.discourse.org/t/how-to-add-action-for-button-in-plugin/153383 "2020-05-31T13:09:28Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![wyudong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wyudong/32/180747_2.png) [@wyudong](https://meta.discourse.org/u/wyudong)\
**Post date:** [May 31, 2020, 1:09pm UTC](https://meta.discourse.org/t/how-to-add-action-for-button-in-plugin/153383/1 "2020-05-31T13:09:29Z")

</div>

I want to make a plugin to show a button and do some action. The button can already be displayed at the desired place, but I don’t know how to create a custom action for it. The file structure is like followings:

```plaintext
plugins/discourse-my-plugin
├── assets
│ ├── javascripts
│ │ └── discourse
│ │ ├── initializers
│ │ │ └── my-plugin.js.es6
│ │ └── templates
│ │ └── connectors
│ │ └── user-messages-nav
│ │ ├── actions.js.es6
│ │ └── button.hbs
├── config
└── plugin.rb

```

**initializers/my-plugin.js.es6**

```js
import { withPluginApi } from "discourse/lib/plugin-api";

function initializeButton(api) {
  api.decoratePluginOutlet('user-messages-nav', (elem, args) => {
    ...
  });
}
export default {
  name: "my-button",
  initialize() {
    withPluginApi("0.8.31", initializeButton);
  }
};

```

**button.hbs**

```plaintext
{{d-button class="btn-primary" action="submitContent" label="submit_content"}}

```

Is it correct to create my custom action like this in **actions.js.es6**? The error is “had no action handler for: submitContent” but how can I fix it?

```js
export default {
  actions: {
    submitContent() {
      ...
    }
  }
};

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-add-action-for-button-in-plugin/153383)._
