question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add toolbar handlers dynamically?

See original GitHub issue

I have a service that has access to the quill editor. (quill variable below)

co-links-module.ts
    ...
    const toolbar = quill.getModule('toolbar');
    if (toolbar) {
      // toolbar.addHandler('quickadd', this.handleQuickadd.bind(this.quill));  // <==== This does not work
      toolbar.addHandler('quickadd', (value) => {  // <==== This does not work
        this.handleQuickadd(value);
      });
    }
    ...

The code snippet runs without errors, however when I click on the custom toolbar button, nothing happens.

If I instead add that handler directly to the config:

editor.component.ts
    ...
    toolbar: {
      container: [
        ['bold', 'italic', 'underline', 'strike'], // toggled buttons
        ...
        ['quickadd'], // link and image and video
      ],
      handlers: {
        ...
        'quickadd': (value) => {
          this.coLinksModule.handleQuickadd(value);  // <==== This does work
        },
      },
    },

And then click the button, it does work. I do not understand why. Not even after hours of trying to wrap my head around it.

I am wondering why I cannot add a handler outside of the config? Any ideas what is going on?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
GitHubishcommented, Dec 1, 2020

@Eraldo I am very interested in the outcome of this exchange. Unfortunately, I have no idea how to help you solve this problem. Maybe you could create an example on Github that we can retrieve for test/debugging?

0reactions
Eraldocommented, Nov 1, 2020

Regarding #1070: I turned off the custom toolbar template for now, so that should not have to do with it at the moment.

Is your handler not executed at all, or is just the handleQuickadd not called.

It is not executed at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically adding buttons to toolbar with click handlers
Dynamically adding buttons to toolbar with click handlers · $(document).ready( function () { · $.post( "/FileReview/DisplayToolbar/" + @ViewBag.
Read more >
ExtJS 4.1 - How to add items to toolbar dynamically?
Is your event handler getting fired? Try adding console.log(win) in the function and see if anything comes out when you show your window....
Read more >
Changing toolbars dynamically at runtime - CodeProject
F ollow the steps below. Create 3 separate Bitmaps in the resource editor with the size to fit the number of buttons on...
Read more >
How to add toolbar tab menu items programmatically
We are looking for a way to add the report names to the dropdown menu of the “Open” toolbar tab at the same...
Read more >
Add Event Handlers to Dynamically Created Toolbar - ZK Fiddle
<toolbarbutton target="_zkdemo" image="/widgets/tabbox/scrollable/img/balloon-facebook-left.png" href="http://www.facebook.com/zk.framework" />.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found