# Chamar uma ação de widget de outro widget

**URL:** <https://meta.discourse.org/t/call-a-widget-action-from-another-widget/234292>\
**Category:** Product Support\
**Created:** [28 Julho , 2022 16:54 UTC](https://meta.discourse.org/t/call-a-widget-action-from-another-widget/234292 "2022-07-28T16:54:55Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![lcor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lcor/32/249044_2.png) [@lcor](https://meta.discourse.org/u/lcor)\
**Post date:** [28 Julho , 2022 16:54 UTC](https://meta.discourse.org/t/call-a-widget-action-from-another-widget/234292/1 "2022-07-28T16:54:55Z")

</div>

Olá,

Gostaria de chamar a ação `toggleSearchMenu` de um widget de botão personalizado que abriria o menu de pesquisa ao ser clicado.

Eu tentei:

```plaintext
  click() {
    this.sendWidgetAction('toggleSearchMenu').then(() => console.log("SENDWIDGETACTION"));
  }

```

Mas ao clicar no meu botão, aparece `toggleSearchMenu not found` no console.

Eu tentei outras formas que `Não funcionam`, como podem ver aqui:

```plaintext
import { createWidget } from "discourse/widgets/widget";
import { iconNode } from "discourse-common/lib/icon-library";
import { h } from 'virtual-dom';

export default createWidget("search-btn-widget", {
  tagName: "div.search-btn-widget",
  buildKey: () => "search-btn-widget",

  html(args) {
    let search_button_helper = "button#search-btn";
    let search_button_class;
    let search_title = "Chercher un sujet";
    let search_text = "Chercher un sujet";
    let search_icon = "ri-small-recherche";
    let search_label_helper = "span.d-button-label";

    if (args == "default") {
      search_button_class = "btn btn-default btn btn-icon-text";
    } else if (args == "primary") {
      search_button_class = "btn btn-primary btn btn-icon-text";
    } else {
      return;
    }

    const toggleSearch = function() {
      this.sendWidgetAction("toggleSearchMenu");
    };

    return h(
      search_button_helper,
      {
        className: search_button_class,
        title: search_title,
        // action: "toggleSearchMenu" => Não funciona
        // onclick: "toggleSearchMenu" => Não funciona
        onclick: toggleSearch
      },
      [iconNode(search_icon), h(search_label_helper, search_text)]
    )
  },
  // click() {
  // this.sendWidgetAction('toggleSearchMenu').then(() => console.log("SENDWIDGETACTION"));
  // } => Não funciona
});

```

Alguma ideia de como eu poderia chamar essa ação do widget dentro do meu widget, se isso for possível?

Muito obrigado 🙏

---

_[View the full topic](https://meta.discourse.org/t/call-a-widget-action-from-another-widget/234292)._
