diff --git a/core/events.js b/core/events.js index 9b9974478..67e210b55 100644 --- a/core/events.js +++ b/core/events.js @@ -550,6 +550,10 @@ Blockly.Events.Change.prototype.run = function(forward) { case 'field': var field = block.getField(this.name); if (field) { + // Run the validator for any side-effects it may have. + // The validator's opinion on validity is ignored. + var validator = field.getValidator(); + validator && validator.call(field, value); field.setValue(value); } else { console.warn("Can't set non-existant field: " + this.name); diff --git a/core/field.js b/core/field.js index 305ecd6d6..4eea423ec 100644 --- a/core/field.js +++ b/core/field.js @@ -232,6 +232,14 @@ Blockly.Field.prototype.setValidator = function(handler) { this.validator_ = handler; }; +/** + * Gets the validation function for editable fields. + * @return {Function} Validation function, or null. + */ +Blockly.Field.prototype.getValidator = function() { + return this.validator_; +}; + /** * Gets the group element for this editable field. * Used for measuring the size and for positioning.