mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
Fix undo on fields with validators with side effects.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user