@formio/js 5.1.0-dev.6194.87d4d3f → 5.1.0-dev.6200.20c037e

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.
@@ -361,6 +361,14 @@ class Webform extends NestedDataComponent_1.default {
361
361
  get shadowRoot() {
362
362
  return this.options.shadowRoot;
363
363
  }
364
+ // Webforms have no default value setting, so this should be always false
365
+ // I does not affect setting default value to nested forms
366
+ get shouldAddDefaultValue() {
367
+ return false;
368
+ }
369
+ get componentsMap() {
370
+ return this.childComponentsMap || {};
371
+ }
364
372
  /**
365
373
  * Add a language for translations
366
374
  * @param {string} code - The language code for the language being added.
@@ -83,8 +83,16 @@ class WebformBuilder extends Component_1.default {
83
83
  }
84
84
  this.groupOrder = this.groupOrder
85
85
  .filter(group => group && !group.ignore)
86
- .sort((a, b) => a.weight - b.weight)
87
- .map(group => group.key);
86
+ .sort((a, b) => a.weight - b.weight);
87
+ const defaultOpenedGroup = this.groupOrder.find(x => x.key !== 'basic' && x.default);
88
+ if (defaultOpenedGroup) {
89
+ this.groupOrder.forEach(x => {
90
+ if ('default' in x && x.key !== defaultOpenedGroup.key) {
91
+ x.default = false;
92
+ }
93
+ });
94
+ }
95
+ this.groupOrder = this.groupOrder.map(group => group.key);
88
96
  for (const type in Components_1.default.components) {
89
97
  const component = Components_1.default.components[type];
90
98
  if (component.builderInfo && component.builderInfo.schema) {
@@ -1099,7 +1107,7 @@ class WebformBuilder extends Component_1.default {
1099
1107
  const newComp = parentComponent.addComponent(defaultValueComponent.component, defaultValueComponent.data, sibling);
1100
1108
  lodash_1.default.pull(newComp.validators, 'required');
1101
1109
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1102
- newComp.checkValidity = () => true;
1110
+ newComp.processOwnValidation = true;
1103
1111
  newComp.build(defaultValueComponent.element);
1104
1112
  if (this.preview && !this.preview.defaultChanged) {
1105
1113
  const defaultValue = lodash_1.default.get(this.preview._data, this.editForm._data.key);
package/lib/cjs/Wizard.js CHANGED
@@ -599,7 +599,7 @@ class Wizard extends Webform_1.default {
599
599
  if (!this._seenPages.includes(parentNum)) {
600
600
  this._seenPages = this._seenPages.concat(parentNum);
601
601
  }
602
- this.redraw().then(() => {
602
+ return this.redraw().then(() => {
603
603
  this.checkData(this.submission.data);
604
604
  this.triggerCaptcha(this.currentPage.components);
605
605
  const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
@@ -607,7 +607,6 @@ class Wizard extends Webform_1.default {
607
607
  this.showErrors(errors, true, true);
608
608
  }
609
609
  });
610
- return Promise.resolve();
611
610
  }
612
611
  else if (!this.pages.length) {
613
612
  this.redraw();
@@ -821,6 +820,11 @@ class Wizard extends Webform_1.default {
821
820
  }
822
821
  }
823
822
  setValue(submission, flags = {}, ignoreEstablishment) {
823
+ if (!submission || !submission.data) {
824
+ submission = {
825
+ data: {},
826
+ };
827
+ }
824
828
  const changed = this.getPages({ all: true }).reduce((changed, page) => {
825
829
  return this.setNestedValue(page, submission.data, flags, changed) || changed;
826
830
  }, false);
@@ -931,10 +935,7 @@ class Wizard extends Webform_1.default {
931
935
  if (pageIndex >= 0) {
932
936
  const page = this.pages[pageIndex];
933
937
  if (page && page !== this.currentPage) {
934
- return this.setPage(pageIndex).then(() => {
935
- this.showErrors(this.validate(this.localData, { dirty: true }));
936
- super.focusOnComponent(key);
937
- });
938
+ return this.setPage(pageIndex).then(() => super.focusOnComponent(key));
938
939
  }
939
940
  }
940
941
  }
@@ -155,7 +155,7 @@ export default class NestedComponent extends Field {
155
155
  * @param {import('@formio/core').Component[]} components - The components to attach logic to.
156
156
  */
157
157
  attachComponentsLogic(components: import('@formio/core').Component[]): void;
158
- attachComponents(element: any, components: any, container: any): Promise<any>;
158
+ attachComponents(element: any, components: any, container: any): Promise<void> | Promise<any[]>;
159
159
  /**
160
160
  * Remove a component from the components array and from the children object
161
161
  * @param {import('@formio/core').Component} component - The component to remove from the components.
@@ -538,8 +538,7 @@ class NestedComponent extends Field_1.default {
538
538
  container = container || this.component.components;
539
539
  element = this.hook('attachComponents', element, components, container, this);
540
540
  if (!element) {
541
- // Return a non-resolving promise.
542
- return (new Promise(() => { }));
541
+ return Promise.resolve();
543
542
  }
544
543
  let index = 0;
545
544
  const promises = [];
@@ -558,12 +557,16 @@ class NestedComponent extends Field_1.default {
558
557
  * @param {boolean} [all] - If set to TRUE will cascade remove all components.
559
558
  */
560
559
  removeComponent(component, components, all = false) {
560
+ var _a, _b;
561
561
  components = components || this.components;
562
562
  component.destroy(all);
563
563
  lodash_1.default.remove(components, { id: component.id });
564
564
  if (this.componentsMap[component.path]) {
565
565
  delete this.componentsMap[component.path];
566
566
  }
567
+ if ((_a = this.root) === null || _a === void 0 ? void 0 : _a.componentsMap[component.path]) {
568
+ (_b = this.root) === null || _b === void 0 ? true : delete _b.componentsMap[component.path];
569
+ }
567
570
  }
568
571
  /**
569
572
  * Removes a component provided the API key of that component.
@@ -838,9 +841,6 @@ class NestedComponent extends Field_1.default {
838
841
  }
839
842
  }
840
843
  setValue(value, flags = {}) {
841
- if (!value) {
842
- return false;
843
- }
844
844
  // If the value is equal to the empty value, then this means we need to reset the values.
845
845
  if (lodash_1.default.isEqual(value, this.emptyValue)) {
846
846
  // TO-DO: For a future major release, we need to investigate removing the need for the
@@ -73,10 +73,10 @@ export default class EditGridComponent extends NestedArrayComponent {
73
73
  rowIndex: any;
74
74
  } | undefined;
75
75
  emptyRow: any;
76
- addRowModal(rowIndex: any): Promise<any>;
76
+ addRowModal(rowIndex: any): Promise<void> | Promise<any[]>;
77
77
  alert: Alert | null | undefined;
78
78
  showDialog(rowIndex: any): Promise<any>;
79
- editRow(rowIndex: any): Promise<any>;
79
+ editRow(rowIndex: any): Promise<void> | Promise<any[]>;
80
80
  clearErrors(rowIndex: any): void;
81
81
  cancelRow(rowIndex: any): void;
82
82
  saveRow(rowIndex: any, modified: any): boolean | undefined;
@@ -29,7 +29,7 @@ export default class FormComponent extends Component {
29
29
  * Prints out the value of form components as a datagrid value.
30
30
  */
31
31
  getValueAsString(value: any, options: any): any;
32
- attach(element: any): Promise<void>;
32
+ attach(element: any): Promise<any>;
33
33
  get hasLoadedForm(): any;
34
34
  get isRevisionChanged(): any;
35
35
  get subFormData(): any;
@@ -290,29 +290,34 @@ class FormComponent extends Component_1.default {
290
290
  return;
291
291
  }
292
292
  this.setContent(element, this.render());
293
+ const postAttach = () => {
294
+ if (!this.builderMode && this.component.modalEdit) {
295
+ const modalShouldBeOpened = this.componentModal ? this.componentModal.isOpened : false;
296
+ const currentValue = modalShouldBeOpened ? this.componentModal.currentValue : this.dataValue;
297
+ this.componentModal = new ComponentModal_1.default(this, element, modalShouldBeOpened, currentValue, this._referenceAttributeName);
298
+ this.subForm.element = this.componentModal.refs.componentContent || this.subForm.element;
299
+ this.setOpenModalElement();
300
+ }
301
+ this.calculateValue();
302
+ };
293
303
  if (this.subForm) {
294
304
  if (this.isNestedWizard) {
295
305
  element = this.root.element;
296
306
  }
297
- this.subForm.attach(element);
298
- this.valueChanged = this.hasSetValue;
299
- if (!this.shouldConditionallyClear()) {
300
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
301
- this.setDefaultValue();
302
- }
303
- else {
304
- this.restoreValue();
307
+ return this.subForm.attach(element).then(() => {
308
+ this.valueChanged = this.hasSetValue;
309
+ if (!this.shouldConditionallyClear()) {
310
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
311
+ this.setDefaultValue();
312
+ }
313
+ else {
314
+ this.restoreValue();
315
+ }
305
316
  }
306
- }
307
- }
308
- if (!this.builderMode && this.component.modalEdit) {
309
- const modalShouldBeOpened = this.componentModal ? this.componentModal.isOpened : false;
310
- const currentValue = modalShouldBeOpened ? this.componentModal.currentValue : this.dataValue;
311
- this.componentModal = new ComponentModal_1.default(this, element, modalShouldBeOpened, currentValue, this._referenceAttributeName);
312
- this.subForm.element = this.componentModal.refs.componentContent || this.subForm.element;
313
- this.setOpenModalElement();
317
+ postAttach();
318
+ });
314
319
  }
315
- this.calculateValue();
320
+ postAttach();
316
321
  });
317
322
  });
318
323
  }
@@ -160,6 +160,13 @@ class TagsComponent extends Input_1.default {
160
160
  this.refs.input[0].parentNode.lastChild.focus();
161
161
  }
162
162
  }
163
+ getValue() {
164
+ if (this.choices) {
165
+ const value = this.choices.getValue(true);
166
+ return value.join(`${this.delimiter}`);
167
+ }
168
+ return super.getValue();
169
+ }
163
170
  getValueAsString(value) {
164
171
  if (!value) {
165
172
  return '';
@@ -333,6 +333,14 @@ export default class Webform extends NestedDataComponent {
333
333
  get shadowRoot() {
334
334
  return this.options.shadowRoot;
335
335
  }
336
+ // Webforms have no default value setting, so this should be always false
337
+ // I does not affect setting default value to nested forms
338
+ get shouldAddDefaultValue() {
339
+ return false;
340
+ }
341
+ get componentsMap() {
342
+ return this.childComponentsMap || {};
343
+ }
336
344
  /**
337
345
  * Add a language for translations
338
346
  * @param {string} code - The language code for the language being added.
@@ -63,8 +63,16 @@ export default class WebformBuilder extends Component {
63
63
  }
64
64
  this.groupOrder = this.groupOrder
65
65
  .filter(group => group && !group.ignore)
66
- .sort((a, b) => a.weight - b.weight)
67
- .map(group => group.key);
66
+ .sort((a, b) => a.weight - b.weight);
67
+ const defaultOpenedGroup = this.groupOrder.find(x => x.key !== 'basic' && x.default);
68
+ if (defaultOpenedGroup) {
69
+ this.groupOrder.forEach(x => {
70
+ if ('default' in x && x.key !== defaultOpenedGroup.key) {
71
+ x.default = false;
72
+ }
73
+ });
74
+ }
75
+ this.groupOrder = this.groupOrder.map(group => group.key);
68
76
  for (const type in Components.components) {
69
77
  const component = Components.components[type];
70
78
  if (component.builderInfo && component.builderInfo.schema) {
@@ -1082,7 +1090,7 @@ export default class WebformBuilder extends Component {
1082
1090
  const newComp = parentComponent.addComponent(defaultValueComponent.component, defaultValueComponent.data, sibling);
1083
1091
  _.pull(newComp.validators, 'required');
1084
1092
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1085
- newComp.checkValidity = () => true;
1093
+ newComp.processOwnValidation = true;
1086
1094
  newComp.build(defaultValueComponent.element);
1087
1095
  if (this.preview && !this.preview.defaultChanged) {
1088
1096
  const defaultValue = _.get(this.preview._data, this.editForm._data.key);
package/lib/mjs/Wizard.js CHANGED
@@ -591,7 +591,7 @@ export default class Wizard extends Webform {
591
591
  if (!this._seenPages.includes(parentNum)) {
592
592
  this._seenPages = this._seenPages.concat(parentNum);
593
593
  }
594
- this.redraw().then(() => {
594
+ return this.redraw().then(() => {
595
595
  this.checkData(this.submission.data);
596
596
  this.triggerCaptcha(this.currentPage.components);
597
597
  const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
@@ -599,7 +599,6 @@ export default class Wizard extends Webform {
599
599
  this.showErrors(errors, true, true);
600
600
  }
601
601
  });
602
- return Promise.resolve();
603
602
  }
604
603
  else if (!this.pages.length) {
605
604
  this.redraw();
@@ -810,6 +809,11 @@ export default class Wizard extends Webform {
810
809
  }
811
810
  }
812
811
  setValue(submission, flags = {}, ignoreEstablishment) {
812
+ if (!submission || !submission.data) {
813
+ submission = {
814
+ data: {},
815
+ };
816
+ }
813
817
  const changed = this.getPages({ all: true }).reduce((changed, page) => {
814
818
  return this.setNestedValue(page, submission.data, flags, changed) || changed;
815
819
  }, false);
@@ -919,10 +923,7 @@ export default class Wizard extends Webform {
919
923
  if (pageIndex >= 0) {
920
924
  const page = this.pages[pageIndex];
921
925
  if (page && page !== this.currentPage) {
922
- return this.setPage(pageIndex).then(() => {
923
- this.showErrors(this.validate(this.localData, { dirty: true }));
924
- super.focusOnComponent(key);
925
- });
926
+ return this.setPage(pageIndex).then(() => super.focusOnComponent(key));
926
927
  }
927
928
  }
928
929
  }
@@ -155,7 +155,7 @@ export default class NestedComponent extends Field {
155
155
  * @param {import('@formio/core').Component[]} components - The components to attach logic to.
156
156
  */
157
157
  attachComponentsLogic(components: import('@formio/core').Component[]): void;
158
- attachComponents(element: any, components: any, container: any): Promise<any>;
158
+ attachComponents(element: any, components: any, container: any): Promise<void> | Promise<any[]>;
159
159
  /**
160
160
  * Remove a component from the components array and from the children object
161
161
  * @param {import('@formio/core').Component} component - The component to remove from the components.
@@ -534,8 +534,7 @@ export default class NestedComponent extends Field {
534
534
  container = container || this.component.components;
535
535
  element = this.hook('attachComponents', element, components, container, this);
536
536
  if (!element) {
537
- // Return a non-resolving promise.
538
- return (new Promise(() => { }));
537
+ return Promise.resolve();
539
538
  }
540
539
  let index = 0;
541
540
  const promises = [];
@@ -560,6 +559,9 @@ export default class NestedComponent extends Field {
560
559
  if (this.componentsMap[component.path]) {
561
560
  delete this.componentsMap[component.path];
562
561
  }
562
+ if (this.root?.componentsMap[component.path]) {
563
+ delete this.root?.componentsMap[component.path];
564
+ }
563
565
  }
564
566
  /**
565
567
  * Removes a component provided the API key of that component.
@@ -833,9 +835,6 @@ export default class NestedComponent extends Field {
833
835
  }
834
836
  }
835
837
  setValue(value, flags = {}) {
836
- if (!value) {
837
- return false;
838
- }
839
838
  // If the value is equal to the empty value, then this means we need to reset the values.
840
839
  if (_.isEqual(value, this.emptyValue)) {
841
840
  // TO-DO: For a future major release, we need to investigate removing the need for the
@@ -73,10 +73,10 @@ export default class EditGridComponent extends NestedArrayComponent {
73
73
  rowIndex: any;
74
74
  } | undefined;
75
75
  emptyRow: any;
76
- addRowModal(rowIndex: any): Promise<any>;
76
+ addRowModal(rowIndex: any): Promise<void> | Promise<any[]>;
77
77
  alert: Alert | null | undefined;
78
78
  showDialog(rowIndex: any): Promise<any>;
79
- editRow(rowIndex: any): Promise<any>;
79
+ editRow(rowIndex: any): Promise<void> | Promise<any[]>;
80
80
  clearErrors(rowIndex: any): void;
81
81
  cancelRow(rowIndex: any): void;
82
82
  saveRow(rowIndex: any, modified: any): boolean | undefined;
@@ -29,7 +29,7 @@ export default class FormComponent extends Component {
29
29
  * Prints out the value of form components as a datagrid value.
30
30
  */
31
31
  getValueAsString(value: any, options: any): any;
32
- attach(element: any): Promise<void>;
32
+ attach(element: any): Promise<any>;
33
33
  get hasLoadedForm(): any;
34
34
  get isRevisionChanged(): any;
35
35
  get subFormData(): any;
@@ -286,29 +286,34 @@ export default class FormComponent extends Component {
286
286
  return;
287
287
  }
288
288
  this.setContent(element, this.render());
289
+ const postAttach = () => {
290
+ if (!this.builderMode && this.component.modalEdit) {
291
+ const modalShouldBeOpened = this.componentModal ? this.componentModal.isOpened : false;
292
+ const currentValue = modalShouldBeOpened ? this.componentModal.currentValue : this.dataValue;
293
+ this.componentModal = new ComponentModal(this, element, modalShouldBeOpened, currentValue, this._referenceAttributeName);
294
+ this.subForm.element = this.componentModal.refs.componentContent || this.subForm.element;
295
+ this.setOpenModalElement();
296
+ }
297
+ this.calculateValue();
298
+ };
289
299
  if (this.subForm) {
290
300
  if (this.isNestedWizard) {
291
301
  element = this.root.element;
292
302
  }
293
- this.subForm.attach(element);
294
- this.valueChanged = this.hasSetValue;
295
- if (!this.shouldConditionallyClear()) {
296
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
297
- this.setDefaultValue();
298
- }
299
- else {
300
- this.restoreValue();
303
+ return this.subForm.attach(element).then(() => {
304
+ this.valueChanged = this.hasSetValue;
305
+ if (!this.shouldConditionallyClear()) {
306
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
307
+ this.setDefaultValue();
308
+ }
309
+ else {
310
+ this.restoreValue();
311
+ }
301
312
  }
302
- }
303
- }
304
- if (!this.builderMode && this.component.modalEdit) {
305
- const modalShouldBeOpened = this.componentModal ? this.componentModal.isOpened : false;
306
- const currentValue = modalShouldBeOpened ? this.componentModal.currentValue : this.dataValue;
307
- this.componentModal = new ComponentModal(this, element, modalShouldBeOpened, currentValue, this._referenceAttributeName);
308
- this.subForm.element = this.componentModal.refs.componentContent || this.subForm.element;
309
- this.setOpenModalElement();
313
+ postAttach();
314
+ });
310
315
  }
311
- this.calculateValue();
316
+ postAttach();
312
317
  });
313
318
  });
314
319
  }
@@ -158,6 +158,13 @@ export default class TagsComponent extends Input {
158
158
  this.refs.input[0].parentNode.lastChild.focus();
159
159
  }
160
160
  }
161
+ getValue() {
162
+ if (this.choices) {
163
+ const value = this.choices.getValue(true);
164
+ return value.join(`${this.delimiter}`);
165
+ }
166
+ return super.getValue();
167
+ }
161
168
  getValueAsString(value) {
162
169
  if (!value) {
163
170
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6194.87d4d3f",
3
+ "version": "5.1.0-dev.6200.20c037e",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {