diff --git a/core/field_textinput.js b/core/field_textinput.js index cf876f91d..3d224c031 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -94,6 +94,18 @@ Blockly.FieldTextInput.prototype.setValue = function(newValue) { Blockly.Field.prototype.setValue.call(this, newValue); }; +/** + * Set the text in this field and fire a change event. + * @param {*} newText New text. + */ +Blockly.FieldTextInput.prototype.setText = function(newText) { + if (this.sourceBlock_ && Blockly.Events.isEnabled()) { + Blockly.Events.fire(new Blockly.Events.Change( + this.sourceBlock_, 'field', this.name, this.text_, newText)); + } + Blockly.Field.prototype.setText.call(this, newText); +}; + /** * Set whether this field is spellchecked by the browser. * @param {boolean} check True if checked.