@formio/js 5.0.0-rc.100 → 5.0.0-rc.101

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.
@@ -12,7 +12,7 @@
12
12
 
13
13
  /*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE */
14
14
 
15
- /*! formiojs v5.0.0-rc.100 | https://unpkg.com/formiojs@5.0.0-rc.100/LICENSE.txt */
15
+ /*! formiojs v5.0.0-rc.101 | https://unpkg.com/formiojs@5.0.0-rc.101/LICENSE.txt */
16
16
 
17
17
  /**
18
18
  * @license
@@ -20,7 +20,7 @@
20
20
 
21
21
  /*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE */
22
22
 
23
- /*! formiojs v5.0.0-rc.100 | https://unpkg.com/formiojs@5.0.0-rc.100/LICENSE.txt */
23
+ /*! formiojs v5.0.0-rc.101 | https://unpkg.com/formiojs@5.0.0-rc.101/LICENSE.txt */
24
24
 
25
25
  /**
26
26
  * @license
@@ -913,13 +913,16 @@ class WebformBuilder extends Component_1.default {
913
913
  keyboardActionsEnabled = keyboardActionsEnabled === 'true';
914
914
  }
915
915
  this.keyboardActionsEnabled = keyboardActionsEnabled;
916
- const isSubmitButton = (comp) => {
917
- return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
918
- };
919
- const isShowSubmitButton = !this.options.noDefaultSubmitButton
920
- && (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));
916
+ const { display, noAddSubmitButton, noDefaultSubmitButton } = this.options;
917
+ const { _id, components } = form;
918
+ const isSubmitButton = ({ type, action }) => type === 'button' && (action === 'submit' || !action);
919
+ const hasSubmitButton = components.some(isSubmitButton);
920
+ // Add submit button if form display was switched from wizard
921
+ // Don't add if there is noAddSubmitButton flag passed, or the form has id, or the form has a submit button already
922
+ const shouldAddSubmitButton = (display === 'wizard' && !hasSubmitButton) ||
923
+ (!noAddSubmitButton && !_id && !hasSubmitButton);
921
924
  // Ensure there is at least a submit button.
922
- if (isShowSubmitButton) {
925
+ if (!noDefaultSubmitButton && shouldAddSubmitButton) {
923
926
  form.components.push({
924
927
  type: 'button',
925
928
  label: 'Submit',
@@ -1094,6 +1097,12 @@ class WebformBuilder extends Component_1.default {
1094
1097
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1095
1098
  newComp.checkValidity = () => true;
1096
1099
  newComp.build(defaultValueComponent.element);
1100
+ if (this.preview && !this.preview.defaultChanged) {
1101
+ const defaultValue = lodash_1.default.get(this.preview._data, this.editForm._data.key);
1102
+ if (lodash_1.default.isObject(defaultValue) && !lodash_1.default.isArray(defaultValue)) {
1103
+ this.editForm._data.defaultValue = defaultValue;
1104
+ }
1105
+ }
1097
1106
  }
1098
1107
  }
1099
1108
  else {
@@ -1104,6 +1113,7 @@ class WebformBuilder extends Component_1.default {
1104
1113
  path.unshift(component.key);
1105
1114
  dataPath = (0, utils_1.getStringFromComponentPath)(path);
1106
1115
  }
1116
+ this.preview.defaultChanged = true;
1107
1117
  lodash_1.default.set(this.preview._data, dataPath, changed.value);
1108
1118
  lodash_1.default.set(this.webform._data, dataPath, changed.value);
1109
1119
  }
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);
@@ -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
  /**
@@ -897,13 +897,16 @@ export default class WebformBuilder extends Component {
897
897
  keyboardActionsEnabled = keyboardActionsEnabled === 'true';
898
898
  }
899
899
  this.keyboardActionsEnabled = keyboardActionsEnabled;
900
- const isSubmitButton = (comp) => {
901
- return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
902
- };
903
- const isShowSubmitButton = !this.options.noDefaultSubmitButton
904
- && (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));
900
+ const { display, noAddSubmitButton, noDefaultSubmitButton } = this.options;
901
+ const { _id, components } = form;
902
+ const isSubmitButton = ({ type, action }) => type === 'button' && (action === 'submit' || !action);
903
+ const hasSubmitButton = components.some(isSubmitButton);
904
+ // Add submit button if form display was switched from wizard
905
+ // Don't add if there is noAddSubmitButton flag passed, or the form has id, or the form has a submit button already
906
+ const shouldAddSubmitButton = (display === 'wizard' && !hasSubmitButton) ||
907
+ (!noAddSubmitButton && !_id && !hasSubmitButton);
905
908
  // Ensure there is at least a submit button.
906
- if (isShowSubmitButton) {
909
+ if (!noDefaultSubmitButton && shouldAddSubmitButton) {
907
910
  form.components.push({
908
911
  type: 'button',
909
912
  label: 'Submit',
@@ -1078,6 +1081,12 @@ export default class WebformBuilder extends Component {
1078
1081
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1079
1082
  newComp.checkValidity = () => true;
1080
1083
  newComp.build(defaultValueComponent.element);
1084
+ if (this.preview && !this.preview.defaultChanged) {
1085
+ const defaultValue = _.get(this.preview._data, this.editForm._data.key);
1086
+ if (_.isObject(defaultValue) && !_.isArray(defaultValue)) {
1087
+ this.editForm._data.defaultValue = defaultValue;
1088
+ }
1089
+ }
1081
1090
  }
1082
1091
  }
1083
1092
  else {
@@ -1088,6 +1097,7 @@ export default class WebformBuilder extends Component {
1088
1097
  path.unshift(component.key);
1089
1098
  dataPath = getStringFromComponentPath(path);
1090
1099
  }
1100
+ this.preview.defaultChanged = true;
1091
1101
  _.set(this.preview._data, dataPath, changed.value);
1092
1102
  _.set(this.webform._data, dataPath, changed.value);
1093
1103
  }
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);
@@ -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-rc.100",
3
+ "version": "5.0.0-rc.101",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {