@formio/js 5.0.0-dev.5923.b428b7b → 5.0.0-dev.5932.9b8cb6d

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.
@@ -901,13 +901,16 @@ class WebformBuilder extends Component_1.default {
901
901
  keyboardActionsEnabled = keyboardActionsEnabled === 'true';
902
902
  }
903
903
  this.keyboardActionsEnabled = keyboardActionsEnabled;
904
- const isSubmitButton = (comp) => {
905
- return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
906
- };
907
- const isShowSubmitButton = !this.options.noDefaultSubmitButton
908
- && (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));
904
+ const { display, noAddSubmitButton, noDefaultSubmitButton } = this.options;
905
+ const { _id, components } = form;
906
+ const isSubmitButton = ({ type, action }) => type === 'button' && (action === 'submit' || !action);
907
+ const hasSubmitButton = components.some(isSubmitButton);
908
+ // Add submit button if form display was switched from wizard
909
+ // Don't add if there is noAddSubmitButton flag passed, or the form has id, or the form has a submit button already
910
+ const shouldAddSubmitButton = (display === 'wizard' && !hasSubmitButton) ||
911
+ (!noAddSubmitButton && !_id && !hasSubmitButton);
909
912
  // Ensure there is at least a submit button.
910
- if (isShowSubmitButton) {
913
+ if (!noDefaultSubmitButton && shouldAddSubmitButton) {
911
914
  form.components.push({
912
915
  type: 'button',
913
916
  label: 'Submit',
@@ -1082,6 +1085,12 @@ class WebformBuilder extends Component_1.default {
1082
1085
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1083
1086
  newComp.checkValidity = () => true;
1084
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
+ }
1085
1094
  }
1086
1095
  }
1087
1096
  else {
@@ -1092,6 +1101,7 @@ class WebformBuilder extends Component_1.default {
1092
1101
  path.unshift(component.key);
1093
1102
  dataPath = (0, utils_1.getStringFromComponentPath)(path);
1094
1103
  }
1104
+ this.preview.defaultChanged = true;
1095
1105
  lodash_1.default.set(this.preview._data, dataPath, changed.value);
1096
1106
  lodash_1.default.set(this.webform._data, dataPath, changed.value);
1097
1107
  }
@@ -105,7 +105,6 @@ declare class Wizard extends Webform {
105
105
  pageId(page: any): any;
106
106
  onChange(flags: any, changed: any, modified: any, changes: any): void;
107
107
  checkValidity(data: any, dirty: any, row: any, currentPageOnly: any, childErrors?: any[]): any;
108
- showErrors(errors: any, triggerEvent: any): void | any[];
109
108
  focusOnComponent(key: any): void | Promise<void>;
110
109
  }
111
110
  declare namespace Wizard {
package/lib/cjs/Wizard.js CHANGED
@@ -720,9 +720,10 @@ class Wizard extends Webform_1.default {
720
720
  }
721
721
  }
722
722
  validateCurrentPage(flags = {}) {
723
- var _a;
723
+ var _a, _b;
724
+ const components = (_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.components.map((component) => component.component);
724
725
  // Accessing the parent ensures the right instance (whether it's the parent Wizard or a nested Wizard) performs its validation
725
- return (_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.parent.validateComponents(this.currentPage.component.components, this.currentPage.parent.data, flags);
726
+ return (_b = this.currentPage) === null || _b === void 0 ? void 0 : _b.parent.validateComponents(components, this.currentPage.parent.data, flags);
726
727
  }
727
728
  emitPrevPage() {
728
729
  this.emit('prevPage', { page: this.page, submission: this.submission });
@@ -864,7 +865,8 @@ class Wizard extends Webform_1.default {
864
865
  onChange(flags, changed, modified, changes) {
865
866
  var _a, _b;
866
867
  super.onChange(flags, changed, modified, changes);
867
- const errors = this.validate(this.localData, { dirty: false });
868
+ // The onChange loop doesn't need all components for wizards
869
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
868
870
  if (this.alert) {
869
871
  this.showErrors(errors, true, true);
870
872
  }
@@ -924,17 +926,6 @@ class Wizard extends Webform_1.default {
924
926
  }
925
927
  return super.errors;
926
928
  }
927
- showErrors(errors, triggerEvent) {
928
- if (this.hasExtraPages) {
929
- this.subWizards.forEach((subWizard) => {
930
- if (Array.isArray(subWizard.errors)) {
931
- errors = [...errors, ...subWizard.errors];
932
- }
933
- });
934
- }
935
- ;
936
- return super.showErrors(errors, triggerEvent);
937
- }
938
929
  focusOnComponent(key) {
939
930
  const component = this.getComponent(key);
940
931
  if (component) {
@@ -476,7 +476,7 @@ class FormComponent extends Component_1.default {
476
476
  checkComponentValidity(data, dirty, row, options, errors = []) {
477
477
  options = options || {};
478
478
  const silentCheck = options.silentCheck || false;
479
- if (this.subForm && !this.isNestedWizard) {
479
+ if (this.subForm) {
480
480
  return this.subForm.checkValidity(this.subFormData, dirty, null, silentCheck, errors);
481
481
  }
482
482
  return super.checkComponentValidity(data, dirty, row, options, 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
  /**
@@ -885,13 +885,16 @@ export default class WebformBuilder extends Component {
885
885
  keyboardActionsEnabled = keyboardActionsEnabled === 'true';
886
886
  }
887
887
  this.keyboardActionsEnabled = keyboardActionsEnabled;
888
- const isSubmitButton = (comp) => {
889
- return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
890
- };
891
- const isShowSubmitButton = !this.options.noDefaultSubmitButton
892
- && (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));
888
+ const { display, noAddSubmitButton, noDefaultSubmitButton } = this.options;
889
+ const { _id, components } = form;
890
+ const isSubmitButton = ({ type, action }) => type === 'button' && (action === 'submit' || !action);
891
+ const hasSubmitButton = components.some(isSubmitButton);
892
+ // Add submit button if form display was switched from wizard
893
+ // Don't add if there is noAddSubmitButton flag passed, or the form has id, or the form has a submit button already
894
+ const shouldAddSubmitButton = (display === 'wizard' && !hasSubmitButton) ||
895
+ (!noAddSubmitButton && !_id && !hasSubmitButton);
893
896
  // Ensure there is at least a submit button.
894
- if (isShowSubmitButton) {
897
+ if (!noDefaultSubmitButton && shouldAddSubmitButton) {
895
898
  form.components.push({
896
899
  type: 'button',
897
900
  label: 'Submit',
@@ -1066,6 +1069,12 @@ export default class WebformBuilder extends Component {
1066
1069
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1067
1070
  newComp.checkValidity = () => true;
1068
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
+ }
1069
1078
  }
1070
1079
  }
1071
1080
  else {
@@ -1076,6 +1085,7 @@ export default class WebformBuilder extends Component {
1076
1085
  path.unshift(component.key);
1077
1086
  dataPath = getStringFromComponentPath(path);
1078
1087
  }
1088
+ this.preview.defaultChanged = true;
1079
1089
  _.set(this.preview._data, dataPath, changed.value);
1080
1090
  _.set(this.webform._data, dataPath, changed.value);
1081
1091
  }
@@ -105,7 +105,6 @@ declare class Wizard extends Webform {
105
105
  pageId(page: any): any;
106
106
  onChange(flags: any, changed: any, modified: any, changes: any): void;
107
107
  checkValidity(data: any, dirty: any, row: any, currentPageOnly: any, childErrors?: any[]): any;
108
- showErrors(errors: any, triggerEvent: any): void | any[];
109
108
  focusOnComponent(key: any): void | Promise<void>;
110
109
  }
111
110
  declare namespace Wizard {
package/lib/mjs/Wizard.js CHANGED
@@ -710,8 +710,9 @@ export default class Wizard extends Webform {
710
710
  }
711
711
  }
712
712
  validateCurrentPage(flags = {}) {
713
+ const components = this.currentPage?.components.map((component) => component.component);
713
714
  // Accessing the parent ensures the right instance (whether it's the parent Wizard or a nested Wizard) performs its validation
714
- return this.currentPage?.parent.validateComponents(this.currentPage.component.components, this.currentPage.parent.data, flags);
715
+ return this.currentPage?.parent.validateComponents(components, this.currentPage.parent.data, flags);
715
716
  }
716
717
  emitPrevPage() {
717
718
  this.emit('prevPage', { page: this.page, submission: this.submission });
@@ -852,7 +853,8 @@ export default class Wizard extends Webform {
852
853
  }
853
854
  onChange(flags, changed, modified, changes) {
854
855
  super.onChange(flags, changed, modified, changes);
855
- const errors = this.validate(this.localData, { dirty: false });
856
+ // The onChange loop doesn't need all components for wizards
857
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
856
858
  if (this.alert) {
857
859
  this.showErrors(errors, true, true);
858
860
  }
@@ -911,17 +913,6 @@ export default class Wizard extends Webform {
911
913
  }
912
914
  return super.errors;
913
915
  }
914
- showErrors(errors, triggerEvent) {
915
- if (this.hasExtraPages) {
916
- this.subWizards.forEach((subWizard) => {
917
- if (Array.isArray(subWizard.errors)) {
918
- errors = [...errors, ...subWizard.errors];
919
- }
920
- });
921
- }
922
- ;
923
- return super.showErrors(errors, triggerEvent);
924
- }
925
916
  focusOnComponent(key) {
926
917
  const component = this.getComponent(key);
927
918
  if (component) {
@@ -470,7 +470,7 @@ export default class FormComponent extends Component {
470
470
  checkComponentValidity(data, dirty, row, options, errors = []) {
471
471
  options = options || {};
472
472
  const silentCheck = options.silentCheck || false;
473
- if (this.subForm && !this.isNestedWizard) {
473
+ if (this.subForm) {
474
474
  return this.subForm.checkValidity(this.subFormData, dirty, null, silentCheck, errors);
475
475
  }
476
476
  return super.checkComponentValidity(data, dirty, row, options, 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.5923.b428b7b",
3
+ "version": "5.0.0-dev.5932.9b8cb6d",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {