@formio/js 5.0.0-dev.5917.280d8f5 → 5.0.0-dev.5920.f58ae24

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.
@@ -808,31 +808,18 @@ class WebformBuilder extends Component_1.default {
808
808
  // Show an error if siblings are disabled for a component and such a component already exists.
809
809
  const compKey = (group === 'resource') ? `component-${key}` : key;
810
810
  const draggableComponent = ((_a = this.groups[group]) === null || _a === void 0 ? void 0 : _a.components[compKey]) || {};
811
- if (draggableComponent.disableSiblings) {
811
+ if (draggableComponent.disableSiblings || draggableComponent.uniqueComponent) {
812
812
  let isCompAlreadyExists = false;
813
813
  (0, formUtils_1.eachComponent)(this.webform.components, (component) => {
814
- if (component.type === draggableComponent.schema.type) {
814
+ if ((draggableComponent.disableSiblings && component.type === draggableComponent.schema.type) ||
815
+ (draggableComponent.uniqueComponent && component.component.key === draggableComponent.schema.key)) {
815
816
  isCompAlreadyExists = true;
816
817
  return;
817
818
  }
818
819
  }, true);
819
820
  if (isCompAlreadyExists) {
820
821
  this.webform.redraw();
821
- this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.key} component to one page.`);
822
- return;
823
- }
824
- }
825
- if (draggableComponent.uniqueComponent) {
826
- let isCompAlreadyExists = false;
827
- (0, formUtils_1.eachComponent)(this.webform.components, (component) => {
828
- if (component.key === draggableComponent.schema.key) {
829
- isCompAlreadyExists = true;
830
- return;
831
- }
832
- }, true);
833
- if (isCompAlreadyExists) {
834
- this.webform.redraw();
835
- this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.title} component to one page.`);
822
+ this.webform.setAlert('danger', `You cannot add more than one ${lodash_1.default.get(draggableComponent, draggableComponent.uniqueComponent ? 'title' : 'key')} component to one page.`);
836
823
  return;
837
824
  }
838
825
  }
@@ -1188,6 +1175,7 @@ class WebformBuilder extends Component_1.default {
1188
1175
  }
1189
1176
  const rebuild = parentComponent.rebuild() || Promise.resolve();
1190
1177
  return rebuild.then(() => {
1178
+ parentComponent.resetValue();
1191
1179
  const schema = parentContainer ? parentContainer[index] : (comp ? comp.schema : []);
1192
1180
  this.emitSaveComponentEvent(schema, originalComp, parentComponent.schema, path, index, isNew, originalComponentSchema);
1193
1181
  this.emit('change', this.form);
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: false }) : this.validateCurrentPage();
868
870
  if (this.alert) {
869
871
  this.showErrors(errors, true, true);
870
872
  }
@@ -925,14 +927,13 @@ class Wizard extends Webform_1.default {
925
927
  return super.errors;
926
928
  }
927
929
  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
- ;
930
+ // if (this.hasExtraPages) {
931
+ // this.subWizards.forEach((subWizard) => {
932
+ // if(Array.isArray(subWizard.errors)) {
933
+ // errors = [...errors, ...subWizard.errors]
934
+ // }
935
+ // })
936
+ // }
936
937
  return super.showErrors(errors, triggerEvent);
937
938
  }
938
939
  focusOnComponent(key) {
@@ -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);
@@ -10,7 +10,6 @@ export default class HiddenComponent extends Input {
10
10
  };
11
11
  get inputInfo(): any;
12
12
  labelIsHidden(): boolean;
13
- get emptyValue(): string;
14
13
  setValue(value: any, flags?: {}): boolean;
15
14
  }
16
15
  import Input from '../_classes/input/Input';
@@ -48,7 +48,7 @@ class HiddenComponent extends Input_1.default {
48
48
  return true;
49
49
  }
50
50
  get emptyValue() {
51
- return '';
51
+ return null;
52
52
  }
53
53
  setValue(value, flags = {}) {
54
54
  return this.updateValue(value, flags);
@@ -1099,6 +1099,7 @@ declare const _default: ({
1099
1099
  alwaysEnabled?: undefined;
1100
1100
  } | {
1101
1101
  key: string;
1102
+ type: string;
1102
1103
  conditional: {
1103
1104
  json: {
1104
1105
  and: ({
@@ -1149,7 +1150,6 @@ declare const _default: ({
1149
1150
  };
1150
1151
  };
1151
1152
  data?: undefined;
1152
- type?: undefined;
1153
1153
  weight?: undefined;
1154
1154
  input?: undefined;
1155
1155
  label?: undefined;
@@ -687,6 +687,7 @@ exports.default = [
687
687
  },
688
688
  {
689
689
  key: 'selectData',
690
+ type: 'hidden',
690
691
  conditional: {
691
692
  json: {
692
693
  and: [
@@ -793,31 +793,18 @@ export default class WebformBuilder extends Component {
793
793
  // Show an error if siblings are disabled for a component and such a component already exists.
794
794
  const compKey = (group === 'resource') ? `component-${key}` : key;
795
795
  const draggableComponent = this.groups[group]?.components[compKey] || {};
796
- if (draggableComponent.disableSiblings) {
796
+ if (draggableComponent.disableSiblings || draggableComponent.uniqueComponent) {
797
797
  let isCompAlreadyExists = false;
798
798
  eachComponent(this.webform.components, (component) => {
799
- if (component.type === draggableComponent.schema.type) {
799
+ if ((draggableComponent.disableSiblings && component.type === draggableComponent.schema.type) ||
800
+ (draggableComponent.uniqueComponent && component.component.key === draggableComponent.schema.key)) {
800
801
  isCompAlreadyExists = true;
801
802
  return;
802
803
  }
803
804
  }, true);
804
805
  if (isCompAlreadyExists) {
805
806
  this.webform.redraw();
806
- this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.key} component to one page.`);
807
- return;
808
- }
809
- }
810
- if (draggableComponent.uniqueComponent) {
811
- let isCompAlreadyExists = false;
812
- eachComponent(this.webform.components, (component) => {
813
- if (component.key === draggableComponent.schema.key) {
814
- isCompAlreadyExists = true;
815
- return;
816
- }
817
- }, true);
818
- if (isCompAlreadyExists) {
819
- this.webform.redraw();
820
- this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.title} component to one page.`);
807
+ this.webform.setAlert('danger', `You cannot add more than one ${_.get(draggableComponent, draggableComponent.uniqueComponent ? 'title' : 'key')} component to one page.`);
821
808
  return;
822
809
  }
823
810
  }
@@ -1172,6 +1159,7 @@ export default class WebformBuilder extends Component {
1172
1159
  }
1173
1160
  const rebuild = parentComponent.rebuild() || Promise.resolve();
1174
1161
  return rebuild.then(() => {
1162
+ parentComponent.resetValue();
1175
1163
  const schema = parentContainer ? parentContainer[index] : (comp ? comp.schema : []);
1176
1164
  this.emitSaveComponentEvent(schema, originalComp, parentComponent.schema, path, index, isNew, originalComponentSchema);
1177
1165
  this.emit('change', this.form);
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: false }) : this.validateCurrentPage();
856
858
  if (this.alert) {
857
859
  this.showErrors(errors, true, true);
858
860
  }
@@ -912,14 +914,13 @@ export default class Wizard extends Webform {
912
914
  return super.errors;
913
915
  }
914
916
  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
- ;
917
+ // if (this.hasExtraPages) {
918
+ // this.subWizards.forEach((subWizard) => {
919
+ // if(Array.isArray(subWizard.errors)) {
920
+ // errors = [...errors, ...subWizard.errors]
921
+ // }
922
+ // })
923
+ // }
923
924
  return super.showErrors(errors, triggerEvent);
924
925
  }
925
926
  focusOnComponent(key) {
@@ -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);
@@ -10,7 +10,6 @@ export default class HiddenComponent extends Input {
10
10
  };
11
11
  get inputInfo(): any;
12
12
  labelIsHidden(): boolean;
13
- get emptyValue(): string;
14
13
  setValue(value: any, flags?: {}): boolean;
15
14
  }
16
15
  import Input from '../_classes/input/Input';
@@ -43,7 +43,7 @@ export default class HiddenComponent extends Input {
43
43
  return true;
44
44
  }
45
45
  get emptyValue() {
46
- return '';
46
+ return null;
47
47
  }
48
48
  setValue(value, flags = {}) {
49
49
  return this.updateValue(value, flags);
@@ -1099,6 +1099,7 @@ declare const _default: ({
1099
1099
  alwaysEnabled?: undefined;
1100
1100
  } | {
1101
1101
  key: string;
1102
+ type: string;
1102
1103
  conditional: {
1103
1104
  json: {
1104
1105
  and: ({
@@ -1149,7 +1150,6 @@ declare const _default: ({
1149
1150
  };
1150
1151
  };
1151
1152
  data?: undefined;
1152
- type?: undefined;
1153
1153
  weight?: undefined;
1154
1154
  input?: undefined;
1155
1155
  label?: undefined;
@@ -681,6 +681,7 @@ export default [
681
681
  },
682
682
  {
683
683
  key: 'selectData',
684
+ type: 'hidden',
684
685
  conditional: {
685
686
  json: {
686
687
  and: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5917.280d8f5",
3
+ "version": "5.0.0-dev.5920.f58ae24",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {