diff --git a/core/field.js b/core/field.js
index 2c6328fc8..274bebf86 100644
--- a/core/field.js
+++ b/core/field.js
@@ -858,16 +858,20 @@ Blockly.Field.prototype.setValue = function(newValue) {
return;
}
}
+ var source = this.sourceBlock_;
+ if (source && source.disposed) {
+ doLogging && console.log('source disposed, return');
+ return;
+ }
var oldValue = this.getValue();
if (oldValue === newValue) {
doLogging && console.log('same, return');
- // No change.
return;
}
- if (this.sourceBlock_ && Blockly.Events.isEnabled()) {
+ if (source && Blockly.Events.isEnabled()) {
Blockly.Events.fire(new Blockly.Events.BlockChange(
- this.sourceBlock_, 'field', this.name || null, oldValue, newValue));
+ source, 'field', this.name || null, oldValue, newValue));
}
this.doValueUpdate_(newValue);
if (this.isDirty_) {
diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js
index 47b44317d..0bb9036b6 100644
--- a/tests/blocks/test_blocks.js
+++ b/tests/blocks/test_blocks.js
@@ -1343,6 +1343,22 @@ Blockly.Blocks['test_images_clickhandler'] = {
}
};
+Blockly.Blocks['test_validators_dispose_block'] = {
+ init: function() {
+ this.appendDummyInput()
+ .appendField("dispose block")
+ .appendField(new Blockly.FieldTextInput("default", this.validate), "INPUT");
+ this.setColour(230);
+ this.setCommentText('Any changes to the text cause the block to be disposed');
+ },
+
+ validate: function(newValue) {
+ if (newValue != "default") {
+ this.getSourceBlock().dispose(true);
+ }
+ }
+};
+
Blockly.Blocks['test_validators_text_null'] = {
init: function() {
this.appendDummyInput()
diff --git a/tests/playground.html b/tests/playground.html
index 9f3d5cfd9..bba66449a 100644
--- a/tests/playground.html
+++ b/tests/playground.html
@@ -1677,6 +1677,9 @@ var spaghettiXml = [
+
+
+