Can not call the Custom Widget from the Button


#21

:game_die: 4, 2


#22

Plus, you can use him to keep topics open :grin: (they normally close after about a month)


#23

@discobot display help.


#24

@discobot display help


#25

I currently know how to do the following things:

@discobot start new user

Starts one of the following interactive narratives: new user, advanced user.

@discobot roll 2d6

:game_die: 3, 6

@discobot quote

:left_speech_bubble: Carry out a random act of kindness, with no expectation of reward, safe in the knowledge that one day someone might do the same for you — Princess Diana

@discobot fortune

:crystal_ball: You may rely on it


#26

:grin:


#27

@Best_codes , are there any updates with fixing the bug with the CustomWidget in a button? As I see it still does not work. Thanks!


#28

@Best_codes , even when I add just Button without CustomWidget it gives me the same error (when I click on that btm).


#29

No, I have reported the bug, but it will probably be a while before it is fixed. :confused:


#30

Until the bug is not fixed, here is my solution for those how may interested in:

In the Common code settings, in the “Add your JavaScript” find the button element that you have created and add the onclick listener. Note, that the elements loaded dynamically, so observe that. Also, the current state does not give you the ID of the button element, so I track the actual label like “Open Serial Monitor”. Here is the JS example:

var obsConfig = { childList: true, characterData: true, attributes: false, subtree: true };
var observer = new MutationObserver(function (m) {
    let collection = document.getElementsByClassName('blocklyFlyoutButton');
    for (let btn of collection) {
        if (btn.innerHTML.includes('Open Serial Monitor')) {
            console.log('found');
            btn.onclick = function () {
                console.log('Clicked!!!');
            }
        }
    }
});
observer.observe(document.body, obsConfig);

#31

This is great! I think you should make a new forum post about this, so users can use your solution and bookmark the post. Thanks for your contribution.