-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic dropdown "forgets" option keys when reloaded #2135
Comments
Upon some more investigation it seems that the issue is slightly more complex than my initial post assumed. In my real life use case, the contents of the dropdown is dependent on the parent block, so is empty if the block isn't attached. My dynamic dropdown function reads something like this:
It seems this that causes the options to be displayed incorrectly when the work-space is deserialized as the Is there any easy way to reinitialise the drop-down contents after the drop-down has been attached to a block and the block has been attached to a parent block? |
There's no especially easy way. You would just have to have a bit of extra code that runs after the workspace is loaded that goes through and reinitializes the dropdowns, I think. I've filed #2142 to have us fire an event when the workspace finishes loading. You would then be able to listen for that event and run your code in response. |
With the recent xml parsing changes, this issue seems to be fixed. I tested repro using the new test block
|
Given a dynamic dropdown, i.e. one where
options
is set to a function instead of a fixed array, if that function returns a list of options where the option key is different to the option value, the option key is lost upon reloading the workspace.Expected Behavior
A dynamic dropdown should always show the option key to the user after a workspace using it is reloaded, not the option value.
Actual Behavior
Given a dynamic dropdown, if the workspace containing it is persisted to XML and then later reloaded, the option keys are lost and the option value is shown to the user in the workspace.
Steps to Reproduce
Given a dynamic dropdown function like:
If you have a block on your workspace that uses it, it will show
a
as the option to the user upon being dragged onto the workspace.If you then write the workspace to XML with
Blockly.Xml
, create a new empty workspace and populate it from the XML (again withBlockly.Xml
) it will show the same block with the same dropdown, but this time the option will be shown asb
to the user, i.e. Blockly is treating the option value as the key for display purposes.Additional Information
From what I can see the issue is that the option keys are not represented in the workspace XML and the dropdown does not infer them from the dynamic option function when deserialized.
Strangely, if you open the dropdown to see the options, it highlights the correct one by key.
In my real life use case, the option values are a JSON datastructure, so this looks pretty ugly. Is there any way to force the dropdown to re-initialize the options upon deserialization?
The text was updated successfully, but these errors were encountered: