Hello,
Sadly there is no way to make a single field uneditable without making the whole block uneditable :/
You might be able to get away with using a
serializable label field (I'm not certain about your circumstances). Just know that that's only available in recent versions of Blockly (I think it was added in 2.20190722.0, but it may have been 1.20190419.0).
If you want to add toggleable editablility to fields, it is possible but it will take a bit of work:
Blockly.Field.prototype.editable_ = true;
2. Add a setEditable function in the same file:
Blockly.Field.prototype.setEditable = function(editable) {
this.editable_ = editable;
};
3a. Update the isClickable function if you're using the latest release:
Blockly.Field.prototype.isClickable = function() {
return this.editable_ &&
!!this.sourceBlock_ && this.sourceBlock_.isEditable() &&
!!this.showEditor_ && (typeof this.showEditor_ === 'function');
};
3b. Or update the isCurrentlyEditable function if you're on an older release:
Blockly.Field.prototype.isCurrentlyEditable = function() {
return this.EDITABLE && this.editable_ &&
!!this.sourceBlock_ && this.sourceBlock_.isEditable();
};
4. Then you'll need to add a
JSON extension to your block to set the field's editability.
Blockly.defineBlocksWithJsonArray([
"extensions": ["not_editable_extension"]
}
]);
Blockly.Extensions.register('not_editable_extension',
function() {
this.getField('cycleLength').setEditable(false);
});
5. If you're running in compressed mode (if you followed the fixed size workspace tutorial you're probably running in compressed mode) you'll need to rebuild blockly. Navigate to the root blockly directory through the command line and then run: python build.py core
If you'd like this to be added as a feature of Blockly you can put up a feature request
here :D
I hope that helps! If you have any further questions please reply!
Beka