Skip to content

Commit

Permalink
FIO-9327: Fixed an issue where select boxes default values would beco…
Browse files Browse the repository at this point in the history
…me messed up during builder mode. (#5932)

* FIO-9327: Fixed an issue where select boxes default values would become messed up during builder mode.

* Fixed issue where default would get messed up.

* Fixing tests.

* Fixing tests.
  • Loading branch information
travist authored Dec 3, 2024
1 parent 95d5794 commit 0698685
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/selectboxes/SelectBoxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0698685

Please sign in to comment.