This all works fine and the block changes shape (from value block to statement block) when the 'remove' option is selected:
Changing the shape is done in the validator of the dropdown:
Blockly.Blocks['node_object_get'] = {
init: function () {
this.jsonInit({
"type": "node_object_get",
"message0": "%1 %2 property %3",
"args0": [
{
"type": "field_dropdown",
"name": "action",
"options": [["Get" , "GET" ],
["Has" , "HAS" ],
["Remove", "REMOVE"]]
},
{
"type": "input_value",
"name": "object",
"check": "Object"
},
{
"type": "input_value",
"name": "field_name",
"check": "String"
}
],
"inputsInline": true,
"output": null,
"colour": '#BB8FCE',
"helpUrl": ""
});
// Assign 'this' to a variable for use in both callback functions below.
var thisBlock = this;
this.getField('action').setValidator(function(action) {
if (thisBlock.previousAction !== action) {
if(thisBlock.previousAction) {
thisBlock.unplug(true, true);
}
switch (action) {
case 'REMOVE':
// statement block
thisBlock.setOutput(false);
thisBlock.setPreviousStatement(true);
thisBlock.setNextStatement(true);
break;
case 'HAS':
// value block
thisBlock.setPreviousStatement(false);
thisBlock.setNextStatement(false);
thisBlock.setOutput(true, 'Boolean');
break;
default: // GET
thisBlock.setPreviousStatement(false);
thisBlock.setNextStatement(false);
thisBlock.setOutput(true); // Any type
break;
}
}
thisBlock.previousAction = action;
});
},
mutationToDom: function() {
const actionDropdown = this.getField('action');
const loadedAction = actionDropdown.getValue();
actionDropdown.getValidator().call(this, loadedAction);
},
};
TypeError: Cannot read property 'isConnected' of null
at Object.Blockly.Xml.domToBlockHeadless_ (blockly_compressed.js:1210)
at Object.Blockly.Xml.domToBlock (blockly_compressed.js:1204)
at Object.Blockly.Xml.domToWorkspace (blockly_compressed.js:1200)
at createWorkspace (eval at <anonymous> (vendor.js:2), <anonymous>:32:21)
at Object.oneditprepare (eval at <anonymous> (vendor.js:2), <anonymous>:242:13)
at d (red.min.js:formatted:11466)
at m (red.min.js:formatted:11486)
at Object.open (red.min.js:formatted:12308)
at n (red.min.js:formatted:13213)
at Object.show (red.min.js:formatted:13253)
mutationToDom: function() {
const actionDropdown = this.getField('action');
const action = actionDropdown.getValue();
var container = document.createElement('mutation');
container.setAttribute('action', action);
return container;
},
domToMutation: function(xmlElement) {
const actionDropdown = this.getField('action');
// Get the stored action from the mutator container element
const action = xmlElement.getAttribute('action');
actionDropdown.getValidator().call(this, action);
},
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.