4, 2
Can not call the Custom Widget from the Button
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
3, 6
@discobot quote
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
You may rely on it
@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!
@Best_codes , even when I add just Button without CustomWidget it gives me the same error (when I click on that btm).
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);
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.