question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

During domToWorkspace() child block with FieldDropdown is in workspace's topblock

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rachel-fenichelcommented, Aug 28, 2019

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?

0reactions
ArfyFRcommented, Jan 22, 2020

@samelhusseini , @rachel-fenichel should I open a new issue ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass dropdown value to parent block and display the ...
I am trying to use a block which will have statement input and then another block which is just a dropdown.
Read more >
View Raw - UNPKG
This will return itself if this block is at the top level. ... Workspace; /** * Wrapper to window.alert() that app developers may...
Read more >
WebSVN - f9daq - Path Comparison - /belle2/masterclass/js/ Rev ...
setTooltip('This block handles the histogram creation and filling. Define a number of bins, minimum and maximum of the range and assign a variable...
Read more >
218.58.62.115:18081/gitlab/edgegw_cs/source/-/comm...
+- First, read this page (including the small print at the end). ... Xml.domToWorkspace(xml, workspace); + } +}; + +/** + * Save...
Read more >
Dropdown fields | Blockly - Google Developers
The text is a human-readable string that will be displayed to the user. Dropdown field. Dropdown field with editor open. Dropdown field on ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found