keep validators on option replace

This commit is contained in:
Loren Norman 2025-04-01 13:47:46 -04:00
parent 83b29e5095
commit b97f2c5b84

View file

@ -1,5 +1,7 @@
export const replaceDropdownOptions = function(fieldKey, newOptions) {
const oldValue = this.getFieldValue(fieldKey)
const
oldValidator = this.getField(fieldKey).getValidator(),
oldValue = this.getFieldValue(fieldKey)
// search this block's inputs...
let input, foundFieldAt
@ -27,7 +29,11 @@ export const replaceDropdownOptions = function(fieldKey, newOptions) {
const newField = new Blockly.FieldDropdown(newOptions)
// maintain previous value, if present
// reconnect prior configuration
if(oldValidator) {
newField.setValidator(oldValidator)
}
if(oldValue) {
newField.setValue(oldValue)
}