Hi Everyone,
I've been working on a tool to generate html + css documents with google blockly. As part of this I've created a few blocks where they have a dropdown field that is dynamically updated based on the existence of other blocks.
In order to achieve this I've used a function to generate the drop-down values however I have run into 2 issues with doing this:
1. If the user changes the name of the document that is being referenced, the dropdown value name doesn't currently change with it.
2. When saving the xmldom and reloading it later, some of the dropdowns forget their value and end up getting reset to none. This I believe is based on the order of the blocks in the workspace e.g. blocks at the top of the workspace get loaded first - therefore if their dropdown field is based on a block that is loaded after it - it gets forgotten.
I'd be grateful if anyone has any ideas about a better way to implement this, I'm currently wondering whether I should be using mutations for this perhaps.
This is the current code I've got for generating the dropdowns:
generateOptions: function(){
console.log("generateOptions");
console.log(workspaces);
var results = [["none", "none"]];
// For each blockly workspace we have
// workspaces is a global variable from elsewhere
for(const [key, value] of Object.entries(workspaces)){
// Get a list of all the css document types on this workspace
var css_blocks = value.getBlocksByType("css_document");
//Add the dropdown values for each block
for(var j = 0; j < css_blocks.length; j++){
var name = css_blocks[j].getFieldValue("NAME");
results.push([name, name+".css"]);
}
}
return results;
}
Thanks
Lewis