@formio/js 5.1.0-dev.6024.3b197fc → 5.1.0-dev.6026.13f1bfb

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.
@@ -261,10 +261,23 @@ class WizardBuilder extends WebformBuilder_1.default {
261
261
  if (component instanceof WizardBuilder) {
262
262
  return;
263
263
  }
264
+ if (!window.sessionStorage) {
265
+ return console.warn(this.t('sessionStorageSupportError'));
266
+ }
267
+ // If pasting after the Wizard's page, check if a full Wizard page was copied and pass it to addPage method
264
268
  if (this._form.components.find(comp => lodash_1.default.isEqual(component.component, comp))) {
265
- this.addPage(component);
269
+ const data = window.sessionStorage.getItem('formio.clipboard');
270
+ if (data) {
271
+ const schema = JSON.parse(data);
272
+ // If the copied component is not a Wizard's page, do nothing since we can't paste outside the panel in Wizard
273
+ if (schema.type !== 'panel') {
274
+ return;
275
+ }
276
+ this.addPage(schema);
277
+ }
266
278
  }
267
279
  else {
280
+ // If we are not trying to paster after the current Wizard's page, just pass it to the WebformBuilder
268
281
  return super.pasteComponent(component);
269
282
  }
270
283
  }
@@ -45,16 +45,18 @@ export default class FormComponent extends Component {
45
45
  /**
46
46
  * Create a subform instance.
47
47
  * @param {boolean} [fromAttach] - This function is being called from an `attach` method.
48
+ * @param {boolean} [beforeSubmit] - This function is being called from a `beforeSubmit` method.
48
49
  * @returns {*} - The subform instance.
49
50
  */
50
- createSubForm(fromAttach?: boolean | undefined): any;
51
+ createSubForm(fromAttach?: boolean | undefined, beforeSubmit?: boolean | undefined): any;
51
52
  hideSubmitButton(component: any): void;
52
53
  /**
53
54
  * Load the subform.
54
55
  * @param {boolean} fromAttach - This function is being called from an `attach` method.
56
+ * @param {boolean} beforeSubmit - This function is being called from a `beforeSubmit` method.
55
57
  * @returns {Promise} - The promise that resolves when the subform is loaded.
56
58
  */
57
- loadSubForm(fromAttach: boolean): Promise<any>;
59
+ loadSubForm(fromAttach: boolean, beforeSubmit: boolean): Promise<any>;
58
60
  subFormLoading: boolean | undefined;
59
61
  checkComponentConditions(data: any, flags: any, row: any): any;
60
62
  calculateValue(data: any, flags: any, row: any): any;
@@ -380,10 +380,11 @@ class FormComponent extends Component_1.default {
380
380
  /**
381
381
  * Create a subform instance.
382
382
  * @param {boolean} [fromAttach] - This function is being called from an `attach` method.
383
+ * @param {boolean} [beforeSubmit] - This function is being called from a `beforeSubmit` method.
383
384
  * @returns {*} - The subform instance.
384
385
  */
385
- createSubForm(fromAttach) {
386
- this.subFormReady = this.loadSubForm(fromAttach).then((form) => {
386
+ createSubForm(fromAttach, beforeSubmit) {
387
+ this.subFormReady = this.loadSubForm(fromAttach, beforeSubmit).then((form) => {
387
388
  if (!form) {
388
389
  return;
389
390
  }
@@ -440,11 +441,13 @@ class FormComponent extends Component_1.default {
440
441
  /**
441
442
  * Load the subform.
442
443
  * @param {boolean} fromAttach - This function is being called from an `attach` method.
444
+ * @param {boolean} beforeSubmit - This function is being called from a `beforeSubmit` method.
443
445
  * @returns {Promise} - The promise that resolves when the subform is loaded.
444
446
  */
445
- loadSubForm(fromAttach) {
447
+ loadSubForm(fromAttach, beforeSubmit) {
446
448
  var _a, _b, _c, _d, _e;
447
- if (this.builderMode || this.conditionallyHidden || (this.isSubFormLazyLoad() && !fromAttach)) {
449
+ const loadHiddenForm = beforeSubmit && !this.component.clearOnHide;
450
+ if (this.builderMode || (this.conditionallyHidden && !loadHiddenForm) || (this.isSubFormLazyLoad() && !fromAttach)) {
448
451
  return Promise.resolve();
449
452
  }
450
453
  if (this.hasLoadedForm && !this.isRevisionChanged &&
@@ -516,7 +519,7 @@ class FormComponent extends Component_1.default {
516
519
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
517
520
  */
518
521
  get shouldSubmit() {
519
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.conditionallyHidden;
522
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && (!this.conditionallyHidden || !this.component.clearOnHide);
520
523
  }
521
524
  /**
522
525
  * Returns the data for the subform.
@@ -587,8 +590,10 @@ class FormComponent extends Component_1.default {
587
590
  this.dataValue = submission;
588
591
  return Promise.resolve(this.dataValue);
589
592
  }
590
- if (this.isSubFormLazyLoad() && !this.subFormLoading) {
591
- return this.createSubForm(true)
593
+ // we need to load a hidden form (when clearOnHide is disabled) in order to get and submit (if needed) its data
594
+ const loadHiddenForm = !this.subForm && !this.component.clearOnHide;
595
+ if ((this.isSubFormLazyLoad() || loadHiddenForm) && !this.subFormLoading) {
596
+ return this.createSubForm(true, true)
592
597
  .then(this.submitSubForm(false))
593
598
  .then(() => {
594
599
  return this.dataValue;
@@ -255,10 +255,23 @@ export default class WizardBuilder extends WebformBuilder {
255
255
  if (component instanceof WizardBuilder) {
256
256
  return;
257
257
  }
258
+ if (!window.sessionStorage) {
259
+ return console.warn(this.t('sessionStorageSupportError'));
260
+ }
261
+ // If pasting after the Wizard's page, check if a full Wizard page was copied and pass it to addPage method
258
262
  if (this._form.components.find(comp => _.isEqual(component.component, comp))) {
259
- this.addPage(component);
263
+ const data = window.sessionStorage.getItem('formio.clipboard');
264
+ if (data) {
265
+ const schema = JSON.parse(data);
266
+ // If the copied component is not a Wizard's page, do nothing since we can't paste outside the panel in Wizard
267
+ if (schema.type !== 'panel') {
268
+ return;
269
+ }
270
+ this.addPage(schema);
271
+ }
260
272
  }
261
273
  else {
274
+ // If we are not trying to paster after the current Wizard's page, just pass it to the WebformBuilder
262
275
  return super.pasteComponent(component);
263
276
  }
264
277
  }
@@ -45,16 +45,18 @@ export default class FormComponent extends Component {
45
45
  /**
46
46
  * Create a subform instance.
47
47
  * @param {boolean} [fromAttach] - This function is being called from an `attach` method.
48
+ * @param {boolean} [beforeSubmit] - This function is being called from a `beforeSubmit` method.
48
49
  * @returns {*} - The subform instance.
49
50
  */
50
- createSubForm(fromAttach?: boolean | undefined): any;
51
+ createSubForm(fromAttach?: boolean | undefined, beforeSubmit?: boolean | undefined): any;
51
52
  hideSubmitButton(component: any): void;
52
53
  /**
53
54
  * Load the subform.
54
55
  * @param {boolean} fromAttach - This function is being called from an `attach` method.
56
+ * @param {boolean} beforeSubmit - This function is being called from a `beforeSubmit` method.
55
57
  * @returns {Promise} - The promise that resolves when the subform is loaded.
56
58
  */
57
- loadSubForm(fromAttach: boolean): Promise<any>;
59
+ loadSubForm(fromAttach: boolean, beforeSubmit: boolean): Promise<any>;
58
60
  subFormLoading: boolean | undefined;
59
61
  checkComponentConditions(data: any, flags: any, row: any): any;
60
62
  calculateValue(data: any, flags: any, row: any): any;
@@ -375,10 +375,11 @@ export default class FormComponent extends Component {
375
375
  /**
376
376
  * Create a subform instance.
377
377
  * @param {boolean} [fromAttach] - This function is being called from an `attach` method.
378
+ * @param {boolean} [beforeSubmit] - This function is being called from a `beforeSubmit` method.
378
379
  * @returns {*} - The subform instance.
379
380
  */
380
- createSubForm(fromAttach) {
381
- this.subFormReady = this.loadSubForm(fromAttach).then((form) => {
381
+ createSubForm(fromAttach, beforeSubmit) {
382
+ this.subFormReady = this.loadSubForm(fromAttach, beforeSubmit).then((form) => {
382
383
  if (!form) {
383
384
  return;
384
385
  }
@@ -435,10 +436,12 @@ export default class FormComponent extends Component {
435
436
  /**
436
437
  * Load the subform.
437
438
  * @param {boolean} fromAttach - This function is being called from an `attach` method.
439
+ * @param {boolean} beforeSubmit - This function is being called from a `beforeSubmit` method.
438
440
  * @returns {Promise} - The promise that resolves when the subform is loaded.
439
441
  */
440
- loadSubForm(fromAttach) {
441
- if (this.builderMode || this.conditionallyHidden || (this.isSubFormLazyLoad() && !fromAttach)) {
442
+ loadSubForm(fromAttach, beforeSubmit) {
443
+ const loadHiddenForm = beforeSubmit && !this.component.clearOnHide;
444
+ if (this.builderMode || (this.conditionallyHidden && !loadHiddenForm) || (this.isSubFormLazyLoad() && !fromAttach)) {
442
445
  return Promise.resolve();
443
446
  }
444
447
  if (this.hasLoadedForm && !this.isRevisionChanged &&
@@ -510,7 +513,7 @@ export default class FormComponent extends Component {
510
513
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
511
514
  */
512
515
  get shouldSubmit() {
513
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.conditionallyHidden;
516
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && (!this.conditionallyHidden || !this.component.clearOnHide);
514
517
  }
515
518
  /**
516
519
  * Returns the data for the subform.
@@ -580,8 +583,10 @@ export default class FormComponent extends Component {
580
583
  this.dataValue = submission;
581
584
  return Promise.resolve(this.dataValue);
582
585
  }
583
- if (this.isSubFormLazyLoad() && !this.subFormLoading) {
584
- return this.createSubForm(true)
586
+ // we need to load a hidden form (when clearOnHide is disabled) in order to get and submit (if needed) its data
587
+ const loadHiddenForm = !this.subForm && !this.component.clearOnHide;
588
+ if ((this.isSubFormLazyLoad() || loadHiddenForm) && !this.subFormLoading) {
589
+ return this.createSubForm(true, true)
585
590
  .then(this.submitSubForm(false))
586
591
  .then(() => {
587
592
  return this.dataValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6024.3b197fc",
3
+ "version": "5.1.0-dev.6026.13f1bfb",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {