@formio/js 5.0.0-dev.5933.606556f → 5.0.0-dev.5935.c16c9d9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1085,6 +1085,12 @@ class WebformBuilder extends Component_1.default {
1085
1085
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1086
1086
  newComp.checkValidity = () => true;
1087
1087
  newComp.build(defaultValueComponent.element);
1088
+ if (this.preview && !this.preview.defaultChanged) {
1089
+ const defaultValue = lodash_1.default.get(this.preview._data, this.editForm._data.key);
1090
+ if (lodash_1.default.isObject(defaultValue) && !lodash_1.default.isArray(defaultValue)) {
1091
+ this.editForm._data.defaultValue = defaultValue;
1092
+ }
1093
+ }
1088
1094
  }
1089
1095
  }
1090
1096
  else {
@@ -1095,6 +1101,7 @@ class WebformBuilder extends Component_1.default {
1095
1101
  path.unshift(component.key);
1096
1102
  dataPath = (0, utils_1.getStringFromComponentPath)(path);
1097
1103
  }
1104
+ this.preview.defaultChanged = true;
1098
1105
  lodash_1.default.set(this.preview._data, dataPath, changed.value);
1099
1106
  lodash_1.default.set(this.webform._data, dataPath, changed.value);
1100
1107
  }
package/lib/cjs/Wizard.js CHANGED
@@ -602,7 +602,10 @@ class Wizard extends Webform_1.default {
602
602
  }
603
603
  this.redraw().then(() => {
604
604
  this.checkData(this.submission.data);
605
- this.validateCurrentPage();
605
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
606
+ if (this.alert) {
607
+ this.showErrors(errors, true, true);
608
+ }
606
609
  });
607
610
  return Promise.resolve();
608
611
  }
@@ -699,9 +702,11 @@ class Wizard extends Webform_1.default {
699
702
  });
700
703
  });
701
704
  }
702
- // Validate the form, before go to the next page
703
- const errors = this.validateCurrentPage({ dirty: true });
704
- if (errors.length === 0) {
705
+ // Validate the form before going to the next page
706
+ const currentPageErrors = this.validateCurrentPage({ dirty: true });
707
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : currentPageErrors;
708
+ // allow going to the next page if the current page is valid, even if there are form level errors
709
+ if (currentPageErrors.length === 0) {
705
710
  this.checkData(this.submission.data);
706
711
  return this.beforePage(true).then(() => {
707
712
  return this.setPage(this.getNextPage()).then(() => {
@@ -716,7 +721,7 @@ class Wizard extends Webform_1.default {
716
721
  else {
717
722
  this.currentPage.components.forEach((comp) => comp.setPristine(false));
718
723
  this.scrollIntoView(this.element, true);
719
- return Promise.reject(super.showErrors(errors, true));
724
+ return Promise.reject(this.showErrors(errors, true));
720
725
  }
721
726
  }
722
727
  validateCurrentPage(flags = {}) {
@@ -921,10 +926,7 @@ class Wizard extends Webform_1.default {
921
926
  return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, currentPageOnly, childErrors) && check, true);
922
927
  }
923
928
  get errors() {
924
- if (!this.isLastPage()) {
925
- return this.currentPage.errors;
926
- }
927
- return super.errors;
929
+ return !this.isLastPage() && !this.submitted ? this.currentPage.errors : super.errors;
928
930
  }
929
931
  focusOnComponent(key) {
930
932
  const component = this.getComponent(key);
@@ -413,7 +413,6 @@ class DataGridComponent extends NestedArrayComponent_1.default {
413
413
  });
414
414
  this.checkConditions();
415
415
  this.triggerChange();
416
- this.triggerChange({ modified: true });
417
416
  this.redraw().then(() => {
418
417
  this.focusOnNewRowElement(this.rows[index]);
419
418
  });
@@ -493,9 +492,6 @@ class DataGridComponent extends NestedArrayComponent_1.default {
493
492
  const options = lodash_1.default.clone(this.options);
494
493
  options.name += `[${rowIndex}]`;
495
494
  options.row = `${rowIndex}-${colIndex}`;
496
- options.onChange = (flags, changed, modified) => {
497
- this.triggerChange({ modified });
498
- };
499
495
  let columnComponent;
500
496
  if (this.builderMode) {
501
497
  col.id = col.id + rowIndex;
@@ -987,7 +987,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
987
987
  dirty;
988
988
  }
989
989
  validateRow(editRow, dirty, forceSilentCheck, fromSubmission) {
990
- var _a;
990
+ var _a, _b;
991
991
  editRow.errors = [];
992
992
  if (this.shouldValidateRow(editRow, dirty, fromSubmission)) {
993
993
  const silentCheck = (this.component.rowDrafts && !this.shouldValidateDraft(editRow)) || forceSilentCheck;
@@ -1037,9 +1037,12 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1037
1037
  });
1038
1038
  }
1039
1039
  }
1040
- if (!this.component.rowDrafts || ((_a = this.root) === null || _a === void 0 ? void 0 : _a.submitted)) {
1040
+ if (editRow.alerts && (!this.component.rowDrafts || ((_a = this.root) === null || _a === void 0 ? void 0 : _a.submitted))) {
1041
1041
  this.showRowErrorAlerts(editRow, editRow.errors);
1042
1042
  }
1043
+ else if ((_b = editRow.errors) === null || _b === void 0 ? void 0 : _b.length) {
1044
+ this.setCustomValidity(editRow.errors, dirty);
1045
+ }
1043
1046
  return editRow.errors;
1044
1047
  }
1045
1048
  showRowErrorAlerts(editRow, errors) {
@@ -139,6 +139,14 @@ class SelectBoxesComponent extends Radio_1.default {
139
139
  checkedValues.forEach((value) => selectData.push(this.templateData[value]));
140
140
  lodash_1.default.set(submission.metadata.selectData, this.path, selectData);
141
141
  }
142
+ // Ensure that for dataSrc == 'values' that there are not any other superfluous values.
143
+ if (this.component.dataSrc === 'values') {
144
+ for (const key in value) {
145
+ if (!this.component.values.find((val) => val.value === key)) {
146
+ delete value[key];
147
+ }
148
+ }
149
+ }
142
150
  return value;
143
151
  }
144
152
  /**
@@ -1069,6 +1069,12 @@ export default class WebformBuilder extends Component {
1069
1069
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1070
1070
  newComp.checkValidity = () => true;
1071
1071
  newComp.build(defaultValueComponent.element);
1072
+ if (this.preview && !this.preview.defaultChanged) {
1073
+ const defaultValue = _.get(this.preview._data, this.editForm._data.key);
1074
+ if (_.isObject(defaultValue) && !_.isArray(defaultValue)) {
1075
+ this.editForm._data.defaultValue = defaultValue;
1076
+ }
1077
+ }
1072
1078
  }
1073
1079
  }
1074
1080
  else {
@@ -1079,6 +1085,7 @@ export default class WebformBuilder extends Component {
1079
1085
  path.unshift(component.key);
1080
1086
  dataPath = getStringFromComponentPath(path);
1081
1087
  }
1088
+ this.preview.defaultChanged = true;
1082
1089
  _.set(this.preview._data, dataPath, changed.value);
1083
1090
  _.set(this.webform._data, dataPath, changed.value);
1084
1091
  }
package/lib/mjs/Wizard.js CHANGED
@@ -594,7 +594,10 @@ export default class Wizard extends Webform {
594
594
  }
595
595
  this.redraw().then(() => {
596
596
  this.checkData(this.submission.data);
597
- this.validateCurrentPage();
597
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
598
+ if (this.alert) {
599
+ this.showErrors(errors, true, true);
600
+ }
598
601
  });
599
602
  return Promise.resolve();
600
603
  }
@@ -689,9 +692,11 @@ export default class Wizard extends Webform {
689
692
  });
690
693
  });
691
694
  }
692
- // Validate the form, before go to the next page
693
- const errors = this.validateCurrentPage({ dirty: true });
694
- if (errors.length === 0) {
695
+ // Validate the form before going to the next page
696
+ const currentPageErrors = this.validateCurrentPage({ dirty: true });
697
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : currentPageErrors;
698
+ // allow going to the next page if the current page is valid, even if there are form level errors
699
+ if (currentPageErrors.length === 0) {
695
700
  this.checkData(this.submission.data);
696
701
  return this.beforePage(true).then(() => {
697
702
  return this.setPage(this.getNextPage()).then(() => {
@@ -706,7 +711,7 @@ export default class Wizard extends Webform {
706
711
  else {
707
712
  this.currentPage.components.forEach((comp) => comp.setPristine(false));
708
713
  this.scrollIntoView(this.element, true);
709
- return Promise.reject(super.showErrors(errors, true));
714
+ return Promise.reject(this.showErrors(errors, true));
710
715
  }
711
716
  }
712
717
  validateCurrentPage(flags = {}) {
@@ -908,10 +913,7 @@ export default class Wizard extends Webform {
908
913
  return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, currentPageOnly, childErrors) && check, true);
909
914
  }
910
915
  get errors() {
911
- if (!this.isLastPage()) {
912
- return this.currentPage.errors;
913
- }
914
- return super.errors;
916
+ return !this.isLastPage() && !this.submitted ? this.currentPage.errors : super.errors;
915
917
  }
916
918
  focusOnComponent(key) {
917
919
  const component = this.getComponent(key);
@@ -410,7 +410,6 @@ export default class DataGridComponent extends NestedArrayComponent {
410
410
  });
411
411
  this.checkConditions();
412
412
  this.triggerChange();
413
- this.triggerChange({ modified: true });
414
413
  this.redraw().then(() => {
415
414
  this.focusOnNewRowElement(this.rows[index]);
416
415
  });
@@ -489,9 +488,6 @@ export default class DataGridComponent extends NestedArrayComponent {
489
488
  const options = _.clone(this.options);
490
489
  options.name += `[${rowIndex}]`;
491
490
  options.row = `${rowIndex}-${colIndex}`;
492
- options.onChange = (flags, changed, modified) => {
493
- this.triggerChange({ modified });
494
- };
495
491
  let columnComponent;
496
492
  if (this.builderMode) {
497
493
  col.id = col.id + rowIndex;
@@ -1026,9 +1026,12 @@ export default class EditGridComponent extends NestedArrayComponent {
1026
1026
  });
1027
1027
  }
1028
1028
  }
1029
- if (!this.component.rowDrafts || this.root?.submitted) {
1029
+ if (editRow.alerts && (!this.component.rowDrafts || this.root?.submitted)) {
1030
1030
  this.showRowErrorAlerts(editRow, editRow.errors);
1031
1031
  }
1032
+ else if (editRow.errors?.length) {
1033
+ this.setCustomValidity(editRow.errors, dirty);
1034
+ }
1032
1035
  return editRow.errors;
1033
1036
  }
1034
1037
  showRowErrorAlerts(editRow, errors) {
@@ -141,6 +141,14 @@ export default class SelectBoxesComponent extends RadioComponent {
141
141
  checkedValues.forEach((value) => selectData.push(this.templateData[value]));
142
142
  _.set(submission.metadata.selectData, this.path, selectData);
143
143
  }
144
+ // Ensure that for dataSrc == 'values' that there are not any other superfluous values.
145
+ if (this.component.dataSrc === 'values') {
146
+ for (const key in value) {
147
+ if (!this.component.values.find((val) => val.value === key)) {
148
+ delete value[key];
149
+ }
150
+ }
151
+ }
144
152
  return value;
145
153
  }
146
154
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5933.606556f",
3
+ "version": "5.0.0-dev.5935.c16c9d9",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {