mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
fix: Group field validator changes with field value changes. (#8589)
This commit is contained in:
105
core/field.ts
105
core/field.ts
@@ -1086,57 +1086,68 @@ export abstract class Field<T = any>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const classValidation = this.doClassValidation_(newValue);
|
// Field validators are allowed to make changes to the workspace, which
|
||||||
const classValue = this.processValidation_(
|
// should get grouped with the field value change event.
|
||||||
newValue,
|
const existingGroup = eventUtils.getGroup();
|
||||||
classValidation,
|
if (!existingGroup) {
|
||||||
fireChangeEvent,
|
eventUtils.setGroup(true);
|
||||||
);
|
|
||||||
if (classValue instanceof Error) {
|
|
||||||
if (doLogging) console.log('invalid class validation, return');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const localValidation = this.getValidator()?.call(this, classValue);
|
try {
|
||||||
const localValue = this.processValidation_(
|
const classValidation = this.doClassValidation_(newValue);
|
||||||
classValue,
|
const classValue = this.processValidation_(
|
||||||
localValidation,
|
newValue,
|
||||||
fireChangeEvent,
|
classValidation,
|
||||||
);
|
fireChangeEvent,
|
||||||
if (localValue instanceof Error) {
|
|
||||||
if (doLogging) console.log('invalid local validation, return');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const source = this.sourceBlock_;
|
|
||||||
if (source && source.disposed) {
|
|
||||||
if (doLogging) console.log('source disposed, return');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const oldValue = this.getValue();
|
|
||||||
if (oldValue === localValue) {
|
|
||||||
if (doLogging) console.log('same, doValueUpdate_, return');
|
|
||||||
this.doValueUpdate_(localValue);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.doValueUpdate_(localValue);
|
|
||||||
if (fireChangeEvent && source && eventUtils.isEnabled()) {
|
|
||||||
eventUtils.fire(
|
|
||||||
new (eventUtils.get(EventType.BLOCK_CHANGE))(
|
|
||||||
source,
|
|
||||||
'field',
|
|
||||||
this.name || null,
|
|
||||||
oldValue,
|
|
||||||
localValue,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
if (classValue instanceof Error) {
|
||||||
|
if (doLogging) console.log('invalid class validation, return');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const localValidation = this.getValidator()?.call(this, classValue);
|
||||||
|
const localValue = this.processValidation_(
|
||||||
|
classValue,
|
||||||
|
localValidation,
|
||||||
|
fireChangeEvent,
|
||||||
|
);
|
||||||
|
if (localValue instanceof Error) {
|
||||||
|
if (doLogging) console.log('invalid local validation, return');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = this.sourceBlock_;
|
||||||
|
if (source && source.disposed) {
|
||||||
|
if (doLogging) console.log('source disposed, return');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldValue = this.getValue();
|
||||||
|
if (oldValue === localValue) {
|
||||||
|
if (doLogging) console.log('same, doValueUpdate_, return');
|
||||||
|
this.doValueUpdate_(localValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.doValueUpdate_(localValue);
|
||||||
|
if (fireChangeEvent && source && eventUtils.isEnabled()) {
|
||||||
|
eventUtils.fire(
|
||||||
|
new (eventUtils.get(EventType.BLOCK_CHANGE))(
|
||||||
|
source,
|
||||||
|
'field',
|
||||||
|
this.name || null,
|
||||||
|
oldValue,
|
||||||
|
localValue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (this.isDirty_) {
|
||||||
|
this.forceRerender();
|
||||||
|
}
|
||||||
|
if (doLogging) console.log(this.value_);
|
||||||
|
} finally {
|
||||||
|
eventUtils.setGroup(existingGroup);
|
||||||
}
|
}
|
||||||
if (this.isDirty_) {
|
|
||||||
this.forceRerender();
|
|
||||||
}
|
|
||||||
if (doLogging) console.log(this.value_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ suite('JSO Serialization', function () {
|
|||||||
},
|
},
|
||||||
'block': {
|
'block': {
|
||||||
'type': 'text',
|
'type': 'text',
|
||||||
'id': 'id3',
|
'id': 'id4',
|
||||||
'fields': {
|
'fields': {
|
||||||
'TEXT': '',
|
'TEXT': '',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user