Blockly: Registering callback for button inside category-less toolbox does not work

Created on 14 Nov 2017  Â·  4Comments  Â·  Source: google/blockly

Problem statement

  • [x] Bug report
  • [ ] Feature request

Registering a callback for a button inside a category-less toolbox never actually gets associated with the button.

Expected Behavior

Clicking the button runs the callback function.

Actual Behavior

Nothing happens when the button is clicked. (A warning appears in the console that the callback wasn't registered.)

Example Code

<xml id="toolbox" style="display: none">
  <button text="test" callbackKey="TEST"></button>
  <block type="controls_if"></block>
</xml>

<script>
  var demoWorkspace = Blockly.inject('blocklyDiv',
    {media: '../../media/', toolbox: document.getElementById('toolbox')});

  demoWorkspace.registerButtonCallback('TEST', function(button) {
    alert("foo");
   });
</script>

Additional Information

Suggested fix: Callbacks should not be associated with the FlyoutButton on instantiation and instead should be dynamically looked up on the click itself.

help wanted bug

All 4 comments

I confirm I have the same problem.
Any workaround ?

Workaround: call workspace.refreshToolboxSelection after calling registerButtonCallback to force it to do another lookup.

Many thanks Rachel.

In my side, I found how to work with it by creating a custom category. Then
it works pretty well and feet to my needs.
Thanks you for your response.

Yann

2018-04-04 18:13 GMT+02:00 Rachel Fenichel notifications@github.com:

Workaround: call workspace.refreshToolboxSelection after calling
registerButtonCallback to force it to do another lookup.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/google/blockly/issues/1446#issuecomment-378657536,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFr6PFExmK_q6tHNlS2WC0r0q3QaViTJks5tlPEegaJpZM4QeEiW
.

--

Avec mes meilleures salutations.
Yann Caron

algoid programming language : http://algoid.net
mail : caron.[email protected]

Fixed by #2196.

Was this page helpful?
0 / 5 - 0 ratings