Fix undo on fields with validators with side effects.

This commit is contained in:
Neil Fraser
2016-06-14 18:42:49 -07:00
parent 02b2c219eb
commit 04ebbb3b76
2 changed files with 12 additions and 0 deletions

View File

@@ -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);

View File

@@ -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.