diff --git a/src/WebformBuilder.js b/src/WebformBuilder.js index 5319106c4b..6a280b9291 100644 --- a/src/WebformBuilder.js +++ b/src/WebformBuilder.js @@ -1243,6 +1243,12 @@ export default class WebformBuilder extends Component { parentComponent.tabs[tabIndex].splice(index, 1, newComp); newComp.checkValidity = () => true; newComp.build(defaultValueComponent.element); + if (this.preview && !this.preview.defaultChanged) { + const defaultValue = _.get(this.preview._data, this.editForm._data.key); + if (_.isObject(defaultValue) && !_.isArray(defaultValue)) { + this.editForm._data.defaultValue = defaultValue; + } + } } } else { @@ -1256,6 +1262,7 @@ export default class WebformBuilder extends Component { dataPath = getStringFromComponentPath(path); } + this.preview.defaultChanged = true; _.set(this.preview._data, dataPath, changed.value); _.set(this.webform._data, dataPath, changed.value); } diff --git a/src/components/selectboxes/SelectBoxes.js b/src/components/selectboxes/SelectBoxes.js index 6919738b63..9dce6cb829 100644 --- a/src/components/selectboxes/SelectBoxes.js +++ b/src/components/selectboxes/SelectBoxes.js @@ -164,6 +164,14 @@ export default class SelectBoxesComponent extends RadioComponent { _.set(submission.metadata.selectData, this.path, selectData); } + // Ensure that for dataSrc == 'values' that there are not any other superfluous values. + if (this.component.dataSrc === 'values') { + for (const key in value) { + if (!this.component.values.find((val) => val.value === key)) { + delete value[key]; + } + } + } return value; }