Skip to content

Commit

Permalink
Merge branch 'master' of github.com:formio/formio.js into refactor-co…
Browse files Browse the repository at this point in the history
…mponent-paths
  • Loading branch information
travist committed Dec 4, 2024
2 parents 9986a3c + 3ff37eb commit f2d1111
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 216 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
25 changes: 12 additions & 13 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,10 @@ export default class Wizard extends Webform {
}
this.redraw().then(() => {
this.checkData(this.submission.data);
this.validateCurrentPage({
dirty: this.submitted
});
const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
if (this.alert) {
this.showErrors(errors, true, true);
}
});
return Promise.resolve();
}
Expand Down Expand Up @@ -803,9 +804,11 @@ export default class Wizard extends Webform {
});
}

// Validate the form, before go to the next page
const errors = this.validateCurrentPage({ dirty: true });
if (errors.length === 0) {
// Validate the form before going to the next page
const currentPageErrors = this.validateCurrentPage({ dirty: true });
const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : currentPageErrors;
// allow going to the next page if the current page is valid, even if there are form level errors
if (currentPageErrors.length === 0) {
this.checkData(this.submission.data);
return this.beforePage(true).then(() => {
return this.setPage(this.getNextPage()).then(() => {
Expand All @@ -821,7 +824,7 @@ export default class Wizard extends Webform {
else {
this.currentPage.components.forEach((comp) => comp.setPristine(false));
this.scrollIntoView(this.element, true);
return Promise.reject(super.showErrors(errors, true));
return Promise.reject(this.showErrors(errors, true));
}
}

Expand Down Expand Up @@ -1062,12 +1065,8 @@ export default class Wizard extends Webform {
);
}

get errors() {
if (!this.isLastPage()) {
return this.currentPage.errors;
}

return super.errors;
get errors() {
return !this.isLastPage() && !this.submitted ? this.currentPage.errors : super.errors;
}

focusOnComponent(key) {
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
140 changes: 140 additions & 0 deletions test/forms/simpleWizardWithRequiredFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
export default {
"_id": "6740b7686f3a02cd736b5750",
"title": "form123",
"name": "form123",
"path": "form123",
"type": "form",
"display": "wizard",
"tags": [],
"access": [
{
"type": "read_all",
"roles": [
"6740b7686f3a02cd736b56f3",
"6740b7686f3a02cd736b56f7",
"6740b7686f3a02cd736b56fb",
"6740b7686f3a02cd736b56ff",
"6740b7686f3a02cd736b5703",
"6740b7686f3a02cd736b5707",
"6740b7686f3a02cd736b570b",
"6740b7686f3a02cd736b570f",
"6740b7686f3a02cd736b5713",
"6740b7686f3a02cd736b5717",
"6740b7686f3a02cd736b571b",
"6740b7686f3a02cd736b571f",
"6740b7686f3a02cd736b5723",
"6740b7686f3a02cd736b5727",
"6740b7686f3a02cd736b572b",
"6740b7686f3a02cd736b572f",
"6740b7686f3a02cd736b5733",
"6740b7686f3a02cd736b5737",
"6740b7686f3a02cd736b573b",
"6740b7686f3a02cd736b573f",
"6740b7686f3a02cd736b5743",
"6740b7686f3a02cd736b5747",
"6740b7686f3a02cd736b574b"
]
}
],
"submissionAccess": [],
"owner": null,
"components": [
{
"title": "Page 1",
"breadcrumbClickable": true,
"buttonSettings": {
"previous": true,
"cancel": false,
"next": true
},
"navigateOnEnter": false,
"saveOnEnter": false,
"scrollToTop": false,
"collapsible": false,
"key": "page1",
"type": "panel",
"label": "Page 1",
"components": [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validate": {
"required": true
},
"key": "textField",
"type": "textfield",
"input": true
}
],
"input": false,
"tableView": false
},
{
"title": "Page 2",
"breadcrumbClickable": true,
"buttonSettings": {
"previous": true,
"cancel": true,
"next": true
},
"navigateOnEnter": false,
"saveOnEnter": false,
"scrollToTop": false,
"collapsible": false,
"key": "page2",
"type": "panel",
"label": "Page 2",
"components": [
{
"label": "Number",
"applyMaskOn": "change",
"mask": false,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"truncateMultipleSpaces": false,
"key": "number",
"type": "number",
"input": true
}
],
"input": false,
"tableView": false
},
{
"title": "Page 3",
"label": "Page 3",
"type": "panel",
"key": "page3",
"components": [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validate": {
"required": true
},
"validateWhenHidden": false,
"key": "textField1",
"type": "textfield",
"input": true
}
],
"input": false,
"tableView": false
}
],
"pdfComponents": [],
"settings": {},
"properties": {},
"machineName": "authoring-bsajzvvuohccvoq:form123",
"project": "6740b7686f3a02cd736b56e9",
"controller": "",
"revisions": "",
"submissionRevisions": "",
"_vid": 0,
"created": "2024-11-22T16:55:04.926Z",
"modified": "2024-11-22T16:55:04.928Z"
};
Loading

0 comments on commit f2d1111

Please sign in to comment.