custom block attribute

286 views
Skip to first unread message

Prabakar Puvanathasan

unread,
Jun 8, 2018, 1:16:15 PM6/8/18
to Blockly
Hi,

I am wondering if we can add custom attributes to block instances via the XML and be able to read and update it dynamically via the block instance in the workspace. 

For example, suppose I have a block for making http request to a URL. Input to the block should be the URL. I also want an attribute called "timeout" that I want to be able to set via an instance of the block (programatically) as well as define it via the XML block definition. This attribute should not be exposed to the UI of the block. Is this possible?

i.e. 

<block id="fsd33dfjdl;kf" type="http_request" timeout="30"></block>
const block = workspaceSvg.getBlockById("fsd33dfjdl;kf")
block.setAttribute("timeout", 25)


thank you
Prabakar

Andrew n marshall

unread,
Jun 11, 2018, 7:13:44 PM6/11/18
to blo...@googlegroups.com
It is not an attribute, or property map, but the block.data string might do what you want. It's value is not exposed to the user. The data field will serialize and deserialize, so its value will persist across sessions. And if you need more than one attribute, you can stringify a JSON map to a string as the data value.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages