Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

saving dynamically created dependent dropdown selections using saveExtraState 0 views Subscribe

52 views
Skip to first unread message

Frank Cappelle

unread,
Jan 21, 2025, 5:48:33 PMJan 21
to Blockly



(I tried to add an image to help explain this better-copy of previous post)

I just haven't had any luck coming up with an answer on my own.


I created a dependent dropdown based on select blocks in the workspace.
So a user selects to measure temperature and adds a temperature block.
That block has 2 options, indoor and outdoor.


I populate a dropdown with two elements; temperature and indoor (or outdoor).
The use selects the options they want.
That selection causes code to be generated that I use with an external device...all good!
This works perfectly.


Without using saveExtraState, the JSON file is populates "GADGET" and "GADGET_PORT" with the code that is generated and not the names of the selected devices (temperature and indoor).


Thus, when I try to use loadExtraState, Blockly doesn't know what to do with ino because it is not the Names of the selected dropdown(s).
Does this make sense.
How can I save and restore the actual language dependent key words that will trigger the dynamic option fill function?


Any help or direction would be greatly appreciated.
Thanks,
Frank

Reply all

Reply to author

Forward

Frank Cappelle

unread,
Jan 21, 2025, 5:51:14 PMJan 21
to Blockly
download.png

feni...@google.com

unread,
Jan 27, 2025, 11:21:07 AMJan 27
to Blockly
Apologies: I sent my response privately instead of publicly. I'm attaching my response and Frank's follow-up.

My response: 

Hi Frank,

Have you looked at the field-dependent-dropdown plugin? It may be able to provide the behaviour you want; if not, you can look at the code to understand how its working and then modify it.

Can you share the JSON that you're getting when you save the block, and a copy showing what you expect to get?

Cheers,
Rachel

Frank's follow-up:

Rachel,
Thank you for taking the time to respond. I really do appreciate your time.

So I did study the field-dependent-dropdown plugin (although not using it currently).
I have been working on this awhile and did it before that was published.
I'll look at it again.

So....
When I save the workspace the JSON file contains the values that the dropdown's create. The language-independent values.
So, (I think) that when the system tries to load them to the workspace or DOM, it doesn't understand the values but might be looking for the labels or text (Human readable?).

Here's the JSON text:
{"blocks":{"languageVersion":0,"blocks":[{"type":"run_forever_loop","id":"QPGz4%tVurf2`(sZEFQr","x":50,"y":50,"inputs":{"loop":{"block":{"type":"gadget_get","id":"v9lj7t?;tV6a2ov2hK;v","extraState":{"firstDropdownValue":"P4 + c@ temperature"},"fields":{"FIRST_DROPDOWN":"P4 + c@ temperature","SECOND_DROPDOWN":"0"},"next":{"block":{"type":"gadget_get","id":"]-[~ZSP}7`Vt8e81R9y*","extraState":{"firstDropdownValue":"P1 + c@ button"},"fields":{"FIRST_DROPDOWN":"P1 + c@ button","SECOND_DROPDOWN":"3"},"next":{"block":{"type":"gadget_get","id":"$T.zsGs.[Aypi`f,LeG~","extraState":{"firstDropdownValue":"P2 + c@ button"},"fields":{"FIRST_DROPDOWN":"P2 + c@ button","SECOND_DROPDOWN":"1"},"next":{"block":{"type":"gadget_get","id":"KsHt]9gk?/dnp8,v}ACD","extraState":{"firstDropdownValue":"P3 + c@ lightlevel"},"fields":{"FIRST_DROPDOWN":"P3 + c@ lightlevel","SECOND_DROPDOWN":"1"}}}}}}}}}}}]}}

I'm experimenting with "extrastate" parameters to see if there is any joy there.

As you may see, the FIRST_DROPDOWN value is the "code" that I want generated, not the "text" that is in the FIRST_DROPDOWN. So when it reloads (In my elementary thinking) it doesn't restore the dropdown text.

I wish I could explain it better :(

If you should want to look at the actual project (I think it's the current iteration):

Most of the blockly workspace gets restored on load, however the dynamically generated dependent dropdown do not.

Thanks so much for your interest.
Frank 

Aaron Dodson

unread,
Jan 31, 2025, 1:10:28 PMJan 31
to Blockly
Hi Frank,

The JSON/serialized version saving the internal/language-independent values is expected, and I don't think is the cause of the problem. In trying your demo, I notice that, in order to have options in the dropdown on the Get Gadget blocks in the StemStacks Builder section, I first need to have selected one or more options on the precreated PORT 1-4 block in the Widgets & Gadgets section. Moreover, in the save file, I see that the StemStacksBuilder is serialized as ws1, and the Widgets & Gadgets section as ws2. Assuming "ws1" is deserialized first, whatever code populates the options for the menu presumably hasn't run yet, so when the dropdown's value is loaded it isn't a valid option. If instead you reversed the order of loading the workspaces and deserialized the Widgets & Gadgets workspace first, I wonder if that might populate the needed options and allow the StemStacks Builder workspace to load properly?

- Aaron

Frank Cappelle

unread,
Jan 31, 2025, 1:34:44 PMJan 31
to Blockly
Oh wow!
That makes a lot of sense. I'll give it a try.
I'm sure it is directly related to pre-loading the category options before they can be loaded or selected. 
I've gone down a lot of rabbit holes trying to solve this, but your idea is noteworthy.

Thanks so much for taking the time to review this and offering a response.

Cheers,
Frank
Reply all
Reply to author
Forward
0 new messages