BlockSvg.setCollapsed how not show the fileds string value

25 views
Skip to first unread message

传贤叶

unread,
Sep 3, 2025, 11:35:35 AM (5 days ago) Sep 3
to Blockly
Hello, all. I need a Block with some invisible but serializable fieds.I create a class InvisibleLabelField extands Blockly.FieldLabelSerializable,and I use render_(){ this.setVisible(false); } to make sure it's invisible.
But When I use SetCollapsed(true) to the Block, fields' string value will show.
How could I do?1.I need keep the fileds' value when I use Blockly.serialization.blocks.save to serialize the Block to string;2.I need hide the fileds in BlockSvg all the time

Mark Friedman

unread,
Sep 3, 2025, 12:14:30 PM (5 days ago) Sep 3
to blo...@googlegroups.com
Given that the field is going to always be invisible, do you really need the field at all?  If you just want to serialize and save some data for a block you could just store the data in the block's data property.  It will automatically get serialized and deserialized along with the block.  You can see the documentation for the data property for blocks here. Note that while that documentation only mentions XML, the data property will also be serialized and deserialized when you use JSON as the serialization format.

Hope this helps.

-Mark


--
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/773ddec6-e481-4f8d-98b1-fdaf34a2057en%40googlegroups.com.

传贤叶

unread,
Sep 4, 2025, 10:51:05 AM (4 days ago) Sep 4
to Blockly
Yeah, I just want to serialize and save some data from the block, data property may be helpful, I'll try it. Thank You

Christopher Allen

unread,
Sep 4, 2025, 12:36:32 PM (4 days ago) Sep 4
to blo...@googlegroups.com
Given that the field is going to always be invisible, do you really need the field at all?  If you just want to serialize and save some data for a block you could just store the data in the block's data property.  It will automatically get serialized and deserialized along with the block.  You can see the documentation for the data property for blocks here. Note that while that documentation only mentions XML, the data property will also be serialized and deserialized when you use JSON as the serialization format.

This is certainly the easiest way to save some additional state when serialising a block, but if that's not sufficient then there's also the optional saveExtraState and loadExtraState methods on block definitions; have a look at some of our library blocks for examples of how this can be used.


Best wishes,

Christopher

Reply all
Reply to author
Forward
0 new messages