Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

setVisible(false) causes bug in Blockly

71 views
Skip to first unread message

Ertis

unread,
Dec 11, 2024, 11:15:24 AM12/11/24
to Blockly
Hi Guys,

i have a question for you.
For some Blocks i want one or more inputparameter(s) of it to be hidden.

So when i am initializing that particular block i try to use the setVisible() Method to variable of type "Blockly.Input". 

For example:

const inputVariable: Blockly.Input = Blockly.appendValue("exampleValue").appendField("exampleId")

inputVariable.setVisible(fallse)

Last line will cause an error.

But what is a bit wird is the fact, that this bug only occurs if use a toolbox search bar.

I hope one of you guys can help me at that point :)

Ronald Bourret

unread,
Dec 11, 2024, 1:06:03 PM12/11/24
to blo...@googlegroups.com
Input.setVisible is marked @internal, which means you shouldn't use it. (See internal.)

Can you explain more about how your application works? Can you use a mutator to add/remove the input?

Thanks,

Ronald Bourret
Technical Writer (Provided by Synergis)


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/blockly/1c5be2bf-f68c-45df-a2b2-0c98b85a55e4n%40googlegroups.com.

Ertis

unread,
Dec 12, 2024, 12:08:42 PM12/12/24
to Blockly
I tried but unfortuinately it did not work for me.

There must be a way to hide an inputfield within a block even when the toolbar ist activated....

Ertis

unread,
Dec 12, 2024, 12:09:01 PM12/12/24
to Blockly
We tried to implemment a mutator which should make thos inputfields invisible but we failed. 

If we are not using a toolbox everything works fine. There is absolutely no problem in using the setVisible(false) method on a variable of type Blockly.Input. There is no error and the inputfield we want to hide is not shown in the GUI. 

However things change when we use a toolbox.

There must be a way to hide certain inputfields even when using the toolbox.

So what is the proper way of doing this?

For example if i want to hide the inputField which is marked red in the picture (see attachment)


rbou...@google.com schrieb am Mittwoch, 11. Dezember 2024 um 19:06:03 UTC+1:
inpufields.png

Ronald Bourret

unread,
Dec 12, 2024, 3:54:09 PM12/12/24
to blo...@googlegroups.com
Hi,

As far as I can tell, there is no publicly available function for setting the visibility of an input. As you have discovered, setVisible does not always work. This is why it is annotated @internal.

One thing you can try is creating and deleting the input based on an event, such as the user connecting a block to the deviceId input. For an example of code that does this, see the @blockly/block-plus-minus Demo. In particular, see the addPart_ and removePart_ functions in text_join.js. In this demo, these functions are triggered by the user clicking on the +/- icons. In your case, they will be triggered by something else.

It is not clear whether you need to implement saveExtraState and loadExtraState and register these as a mutator -- it depends on how you decide whether your recOption input is visible. For more information, see When to save extra state and Mutators.

Note that mutators do not have to use the standard mutator UI (the compose and decompose functions). The +/- demo is an example of a mutator that does not use this UI.

Ronald Bourret
Technical Writer (Provided by Synergis)

Reply all
Reply to author
Forward
0 new messages