Disable blocks on the toolbox

2,242 views
Skip to first unread message

Andres Nebel

unread,
Jan 6, 2014, 6:40:37 AM1/6/14
to blo...@googlegroups.com
Hi everyone,

I'm struggling to find a way to disable specific blocks in the toolbox, but without using the maxblocks property of the workspace. It could be very usefull to have a way to make some blocks of the toolbox "run once", that is, only one block of that kind allowed in the workspace.

A solution could be remove it of the toolbox after drag, but it would be much nicer to disable the block on the toolbox (like when maxblock is equal 0).

Regards

Andres Nebel

Ankur Gupta

unread,
Jan 6, 2014, 7:36:29 AM1/6/14
to blo...@googlegroups.com
I am just learning from the blockly codebase myself so the answer may be wrong. 
But you can modify the 

Blockly.Workspace.prototype.addTopBlock function implementation such that it checks against a counter being maxBlock of a given element and if the maxBlock of the element is 0 it doesn't allow you to add the block no matter how many times you drag and drop. You can use the prototypeName to check which block is which. 

Do note I haven't written the code for the same and am a total noob. See if this works/makes sense.

Regards
Ankur
Message has been deleted

Andres Nebel

unread,
Jan 6, 2014, 4:19:59 PM1/6/14
to blo...@googlegroups.com
Ankur,

Thanks for the reply, that is actually a good idea (despite it doesn't show the disabled block on the toolbox). However i couldn't do it that way, because it was generating some strange behaviours, like that i couldn't get rid of the block i was dragging.

I finally got it working the way i was looking for by overriding the Blockly.Flyout.prototype.filterForCapacity_  function. That is the place where Blockly decides whether to disable the block on the toolbox or not.

Regards

Andres Nebel

Gelarehr

unread,
Feb 18, 2016, 5:24:04 PM2/18/16
to Blockly
I am also having an issue with disabling blocks in Blockly. 

According to the documentation, blocks in a toolbox may be individually disabled using the optional disabled attribute.

I am trying this and it not making any difference to my block:

<block type="move" disabled="true"></block>


Has this worked for anyone before?

Thanks in advance, 
Gelareh

Carlos Pereira

unread,
Feb 19, 2016, 4:27:34 PM2/19/16
to Blockly
Are you using Angular by any chance? Or any other type of framework that could edit the DOM?

Gelarehr

unread,
Feb 20, 2016, 3:38:38 PM2/20/16
to Blockly
No I'm not.

Carlos Pereira

unread,
Feb 20, 2016, 7:51:48 PM2/20/16
to Blockly
The reason I asked is because that was an issue experienced by some people in the past:
https://github.com/google/blockly/pull/229
So I assume that without those types of frameworks it has been working well.

Frédéric CLEMENT

unread,
Aug 25, 2017, 2:33:52 AM8/25/17
to Blockly
Hi

The `disabled="true"`is working for me.
But I wonder if there is a way to use it in an anguler 2/4 mode.

I tried this but it doesnt' work :

<xml id='toolbox'>
<category name='Capteurs'>
<block type='input_numeric' disabled="{{ disabled }}"></block>
<block type='input_boolean'></block>
<block type='input_text'></block>
</category>

If someone had found out how to do it, it would greatly interest me.

Fred



Reply all
Reply to author
Forward
0 new messages