I am new to blockly and have created a custom block where i want certain fields to be disabled based on my selection from a dropdown on the block.
I want the fields "Sheet" and "Macro" to be removed when i select copy_sheet from the dropdown
Blockly.Blocks['excel_functions'] = {
init: function() {
this.FUNCTIONS =
[
["Copy Sheet", 'copy_sheet'],
["Run Macro", 'run_macro'],
["Delete Sheet", 'delete_sheet']
];
this.appendValueInput("excel_opeartions")
.setCheck(null)
.appendField("Excel Operations")
.appendField(new Blockly.FieldDropdown(this.FUNCTIONS, function(option){
var input=this.sourceBlock_.getInput("ti");
if(option=='copy_sheet'){
if(this.sourceBlock_.getInput('destination_path')==null){
this.sourceBlock_.appendValueInput("destination_path")
.setCheck(null)
.appendField("Destination Path");
}
input.removeField("Sheet");
input.removeField('sheet_name');
input.removeField('Macro');
input.removeField('macro_name');
}
}), "excel_options")
.appendField("Source Path");
this.appendValueInput("destination_path")
.setCheck(null)
.appendField("Destination Path");
this.appendDummyInput("ti")
.appendField("Sheet")
.appendField(new Blockly.FieldTextInput("Sheet Name"), "sheet_name")
.appendField("Macro")
.appendField(new Blockly.FieldTextInput("Macro Name"), "macro_name")
.appendField("From Sheet")
.appendField(new Blockly.FieldTextInput("Sheet Name"), "from_sheet")
.appendField("To Sheet")
.appendField(new Blockly.FieldTextInput("Sheet Name"), "to_sheet");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(120);
this.setTooltip('');
this.setHelpUrl('');
}
};