During domToWorkspace() child block with FieldDropdown is in workspace's topblock
See original GitHub issueI updated blockly in a project from 1.20190419.0 to “npm”: “blockly”: “2.20190722.1”
In order to restore a view, I use
Blockly.Xml.domToWorkspace(this.contentData.content, this.workspace);
In our project we only have one top/root block (with childs) by design. Some child blocks have FieldDropdown, which are filled with a function like
new Blockly.FieldDropdown(function createSelectedDataTableField_func() {
let selectedTables = [];
...
return selectedTables;
with FieldDropdown values depending on what is set in the root block.
With Blockly 1.20190419.0 => OK
But with Blockly 2.20190722.1 after domToWorkspace, I faced the following. Traces in console like:
Cannot set the dropdown’s value to an unavailable option. Block type: dataset_field_table_column, Field name: FIELD_TABLE, Value: mapchartbycust
In the createSelectedDataTableField_func() call, the child block’s getRootBlock() is itself O_o
And the workspace has two+ top blocks, the good one and the child(s). So If I call getRootBlock() to do a
let xyz = rootBlock.getFieldValue('SELECTED_TABLE');
call it won’t work anymore.
I had to (bad) hack our code with
if(rootBlock.type == 'dataset_field_table_column') {
rootBlock = rootBlock.workspace.getTopBlocks()[0];
}
to select the “good” root block.
Later, I get the Blockly.Events.BLOCK_CREATE event, and the child(s) block(s) are (back) to root block childs => OK
Expected behavior
Like before
Desktop (please complete the following information):
- OS: Windows 10
- Browser Chrome
- Version 76.0.3809.100
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (2 by maintainers)
Top GitHub Comments
Thanks for the detailed repro information!
This sounds like a change in the initialization order for fields that broke your blocks. It’s not a surprise that blocks are on the workspace when created, and are then attached to the expected parent, but your initialization function must be being called early than it used to be.
@BeksOmega any ideas before I dig in?
@samelhusseini , @rachel-fenichel should I open a new issue ?