@formio/js 5.0.0-dev.5896.56bf2bd → 5.0.0-dev.5902.1eb1690

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.
Files changed (94) hide show
  1. package/Changelog.md +307 -10
  2. package/dist/formio.form.js +602 -590
  3. package/dist/formio.form.min.js +1 -1
  4. package/dist/formio.form.min.js.LICENSE.txt +2 -2
  5. package/dist/formio.full.js +604 -592
  6. package/dist/formio.full.min.js +1 -1
  7. package/dist/formio.full.min.js.LICENSE.txt +2 -2
  8. package/dist/formio.js +3131 -209
  9. package/dist/formio.min.js +1 -1
  10. package/dist/formio.min.js.LICENSE.txt +14 -0
  11. package/dist/formio.utils.js +58 -46
  12. package/dist/formio.utils.min.js +1 -1
  13. package/dist/formio.utils.min.js.LICENSE.txt +2 -2
  14. package/lib/cjs/Webform.d.ts +1 -1
  15. package/lib/cjs/Webform.js +27 -28
  16. package/lib/cjs/WebformBuilder.js +26 -35
  17. package/lib/cjs/Wizard.d.ts +0 -1
  18. package/lib/cjs/Wizard.js +19 -33
  19. package/lib/cjs/components/Components.d.ts +0 -7
  20. package/lib/cjs/components/Components.js +1 -33
  21. package/lib/cjs/components/_classes/component/Component.d.ts +39 -7
  22. package/lib/cjs/components/_classes/component/Component.js +106 -37
  23. package/lib/cjs/components/_classes/component/editForm/Component.edit.data.js +2 -2
  24. package/lib/cjs/components/_classes/component/editForm/Component.edit.validation.js +1 -1
  25. package/lib/cjs/components/_classes/componentModal/ComponentModal.d.ts +1 -0
  26. package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -0
  27. package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +4 -19
  28. package/lib/cjs/components/_classes/nested/NestedComponent.js +54 -60
  29. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -1
  30. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +9 -46
  31. package/lib/cjs/components/datagrid/DataGrid.d.ts +0 -1
  32. package/lib/cjs/components/datagrid/DataGrid.js +1 -45
  33. package/lib/cjs/components/datamap/DataMap.js +2 -3
  34. package/lib/cjs/components/editgrid/EditGrid.js +13 -13
  35. package/lib/cjs/components/form/Form.d.ts +1 -3
  36. package/lib/cjs/components/form/Form.js +20 -28
  37. package/lib/cjs/components/hidden/Hidden.d.ts +0 -1
  38. package/lib/cjs/components/hidden/Hidden.js +1 -1
  39. package/lib/cjs/components/html/HTML.js +15 -3
  40. package/lib/cjs/components/select/editForm/Select.edit.data.d.ts +1 -1
  41. package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -0
  42. package/lib/cjs/components/selectboxes/SelectBoxes.js +8 -1
  43. package/lib/cjs/components/signature/Signature.js +3 -1
  44. package/lib/cjs/utils/conditionOperators/DateGreaterThan.js +2 -2
  45. package/lib/cjs/utils/conditionOperators/IsEmptyValue.d.ts +2 -2
  46. package/lib/cjs/utils/conditionOperators/IsEmptyValue.js +2 -2
  47. package/lib/cjs/utils/conditionOperators/IsEqualTo.d.ts +2 -2
  48. package/lib/cjs/utils/conditionOperators/IsEqualTo.js +2 -2
  49. package/lib/cjs/utils/formUtils.d.ts +25 -14
  50. package/lib/cjs/utils/formUtils.js +11 -16
  51. package/lib/cjs/utils/i18n.js +5 -0
  52. package/lib/cjs/utils/utils.d.ts +1 -2
  53. package/lib/cjs/utils/utils.js +19 -35
  54. package/lib/mjs/Webform.d.ts +1 -1
  55. package/lib/mjs/Webform.js +24 -27
  56. package/lib/mjs/WebformBuilder.js +26 -35
  57. package/lib/mjs/Wizard.d.ts +0 -1
  58. package/lib/mjs/Wizard.js +16 -29
  59. package/lib/mjs/components/Components.d.ts +0 -7
  60. package/lib/mjs/components/Components.js +1 -32
  61. package/lib/mjs/components/_classes/component/Component.d.ts +39 -7
  62. package/lib/mjs/components/_classes/component/Component.js +108 -38
  63. package/lib/mjs/components/_classes/component/editForm/Component.edit.data.js +2 -2
  64. package/lib/mjs/components/_classes/component/editForm/Component.edit.validation.js +1 -1
  65. package/lib/mjs/components/_classes/componentModal/ComponentModal.d.ts +1 -0
  66. package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -0
  67. package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +4 -19
  68. package/lib/mjs/components/_classes/nested/NestedComponent.js +55 -61
  69. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -1
  70. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +8 -43
  71. package/lib/mjs/components/datagrid/DataGrid.d.ts +0 -1
  72. package/lib/mjs/components/datagrid/DataGrid.js +1 -45
  73. package/lib/mjs/components/datamap/DataMap.js +2 -3
  74. package/lib/mjs/components/editgrid/EditGrid.js +15 -12
  75. package/lib/mjs/components/form/Form.d.ts +1 -3
  76. package/lib/mjs/components/form/Form.js +21 -28
  77. package/lib/mjs/components/hidden/Hidden.d.ts +0 -1
  78. package/lib/mjs/components/hidden/Hidden.js +1 -1
  79. package/lib/mjs/components/html/HTML.js +15 -3
  80. package/lib/mjs/components/select/editForm/Select.edit.data.d.ts +1 -1
  81. package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -0
  82. package/lib/mjs/components/selectboxes/SelectBoxes.js +8 -1
  83. package/lib/mjs/components/signature/Signature.js +3 -1
  84. package/lib/mjs/utils/conditionOperators/DateGreaterThan.js +2 -2
  85. package/lib/mjs/utils/conditionOperators/IsEmptyValue.d.ts +2 -2
  86. package/lib/mjs/utils/conditionOperators/IsEmptyValue.js +2 -2
  87. package/lib/mjs/utils/conditionOperators/IsEqualTo.d.ts +2 -2
  88. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +2 -2
  89. package/lib/mjs/utils/formUtils.d.ts +25 -14
  90. package/lib/mjs/utils/formUtils.js +2 -12
  91. package/lib/mjs/utils/i18n.js +4 -0
  92. package/lib/mjs/utils/utils.d.ts +1 -2
  93. package/lib/mjs/utils/utils.js +18 -33
  94. package/package.json +4 -4
@@ -1,22 +1,33 @@
1
- /**
2
- * Deprecated version of findComponents. Renamed to searchComponents.
3
- * @param {import('@formio/core').Component[]} components - The components to find components within.
4
- * @param {object} query - The query to use when searching for the components.
5
- * @returns {import('@formio/core').Component[]} - The result of the component that is found.
6
- */
7
- export function findComponents(components: import('@formio/core').Component[], query: object): import('@formio/core').Component[];
8
1
  export const flattenComponents: typeof Utils.flattenComponents;
9
2
  export const guid: typeof Utils.guid;
10
3
  export const uniqueName: typeof Utils.uniqueName;
11
- export const MODEL_TYPES: any;
4
+ export const MODEL_TYPES_OF_KNOWN_COMPONENTS: {
5
+ nestedArray: string[];
6
+ nestedDataArray: string[];
7
+ dataObject: string[];
8
+ object: string[];
9
+ map: string[];
10
+ content: string[];
11
+ string: string[];
12
+ number: string[];
13
+ boolean: string[];
14
+ none: string[];
15
+ any: string[];
16
+ };
12
17
  export const getModelType: typeof Utils.getModelType;
13
- export const getComponentAbsolutePath: typeof Utils.getComponentAbsolutePath;
14
- export const getComponentPath: typeof Utils.getComponentPath;
18
+ export const getComponentPath: any;
19
+ export const setComponentScope: typeof Utils.setComponentScope;
20
+ export const resetComponentScope: typeof Utils.resetComponentScope;
15
21
  export const isComponentNestedDataType: typeof Utils.isComponentNestedDataType;
16
22
  export const componentPath: typeof Utils.componentPath;
17
- export const componentChildPath: any;
18
- export const eachComponentDataAsync: (components: Component[], data: DataObject, fn: EachComponentDataAsyncCallback, path?: string | undefined, index?: number | undefined, parent?: any, includeAll?: boolean | undefined) => Promise<void>;
19
- export const eachComponentData: (components: Component[], data: DataObject, fn: EachComponentDataCallback, path?: string | undefined, index?: number | undefined, parent?: any, includeAll?: boolean | undefined) => void;
23
+ export const getComponentPaths: typeof Utils.getComponentPaths;
24
+ export const componentMatches: typeof Utils.componentMatches;
25
+ export const getBestMatch: typeof Utils.getBestMatch;
26
+ export const getComponentFromPath: typeof Utils.getComponentFromPath;
27
+ export const getComponentValue: typeof Utils.getComponentValue;
28
+ export const findComponents: typeof Utils.findComponents;
29
+ export const eachComponentDataAsync: (components: Component[], data: DataObject, fn: EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => Promise<void>;
30
+ export const eachComponentData: (components: Component[], data: DataObject, fn: EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => void;
20
31
  export const getComponentKey: typeof Utils.getComponentKey;
21
32
  export const getContextualRowPath: typeof Utils.getContextualRowPath;
22
33
  export const getContextualRowData: typeof Utils.getContextualRowData;
@@ -24,7 +35,7 @@ export const componentInfo: typeof Utils.componentInfo;
24
35
  export const eachComponent: typeof Utils.eachComponent;
25
36
  export const eachComponentAsync: typeof Utils.eachComponentAsync;
26
37
  export const getComponentData: typeof Utils.getComponentData;
27
- export const getComponentActualValue: typeof Utils.getComponentActualValue;
38
+ export const getComponentActualValue: any;
28
39
  export const isLayoutComponent: typeof Utils.isLayoutComponent;
29
40
  export const matchComponent: typeof Utils.matchComponent;
30
41
  export const getComponent: typeof Utils.getComponent;
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getItemTemplateKeys = exports.compareSelectResourceWithObjectTypeValues = exports.isSelectResourceWithObjectValue = exports.isComponentDataEmpty = exports.getEmptyValue = exports.findComponent = exports.applyFormChanges = exports.generateFormChange = exports.getStrings = exports.getValue = exports.escapeRegExCharacters = exports.formatAsCurrency = exports.parseFloatExt = exports.hasCondition = exports.removeComponent = exports.searchComponents = exports.getComponent = exports.matchComponent = exports.isLayoutComponent = exports.getComponentActualValue = exports.getComponentData = exports.eachComponentAsync = exports.eachComponent = exports.componentInfo = exports.getContextualRowData = exports.getContextualRowPath = exports.getComponentKey = exports.eachComponentData = exports.eachComponentDataAsync = exports.componentChildPath = exports.componentPath = exports.isComponentNestedDataType = exports.getComponentPath = exports.getComponentAbsolutePath = exports.getModelType = exports.MODEL_TYPES = exports.uniqueName = exports.guid = exports.flattenComponents = exports.findComponents = void 0;
3
+ exports.getItemTemplateKeys = exports.compareSelectResourceWithObjectTypeValues = exports.isSelectResourceWithObjectValue = exports.isComponentDataEmpty = exports.getEmptyValue = exports.findComponent = exports.applyFormChanges = exports.generateFormChange = exports.getStrings = exports.getValue = exports.escapeRegExCharacters = exports.formatAsCurrency = exports.parseFloatExt = exports.hasCondition = exports.removeComponent = exports.searchComponents = exports.getComponent = exports.matchComponent = exports.isLayoutComponent = exports.getComponentActualValue = exports.getComponentData = exports.eachComponentAsync = exports.eachComponent = exports.componentInfo = exports.getContextualRowData = exports.getContextualRowPath = exports.getComponentKey = exports.eachComponentData = exports.eachComponentDataAsync = exports.findComponents = exports.getComponentValue = exports.getComponentFromPath = exports.getBestMatch = exports.componentMatches = exports.getComponentPaths = exports.componentPath = exports.isComponentNestedDataType = exports.resetComponentScope = exports.setComponentScope = exports.getComponentPath = exports.getModelType = exports.MODEL_TYPES_OF_KNOWN_COMPONENTS = exports.uniqueName = exports.guid = exports.flattenComponents = void 0;
4
4
  const core_1 = require("@formio/core");
5
- const { flattenComponents, guid, uniqueName, MODEL_TYPES, getModelType, getComponentAbsolutePath, getComponentPath, isComponentNestedDataType, componentPath, componentChildPath, eachComponentDataAsync, eachComponentData, getComponentKey, getContextualRowPath, getContextualRowData, componentInfo, eachComponent, eachComponentAsync, getComponentData, getComponentActualValue, isLayoutComponent, matchComponent, getComponent, searchComponents, removeComponent, hasCondition, parseFloatExt, formatAsCurrency, escapeRegExCharacters, getValue, getStrings, generateFormChange, applyFormChanges, findComponent, getEmptyValue, isComponentDataEmpty, isSelectResourceWithObjectValue, compareSelectResourceWithObjectTypeValues, getItemTemplateKeys } = core_1.Utils;
5
+ const { flattenComponents, guid, uniqueName, MODEL_TYPES_OF_KNOWN_COMPONENTS, getModelType, getComponentPath, setComponentScope, resetComponentScope, isComponentNestedDataType, componentPath, getComponentPaths, componentMatches, getBestMatch, getComponentFromPath, getComponentValue, findComponents, eachComponentDataAsync, eachComponentData, getComponentKey, getContextualRowPath, getContextualRowData, componentInfo, eachComponent, eachComponentAsync, getComponentData, getComponentActualValue, isLayoutComponent, matchComponent, getComponent, searchComponents, removeComponent, hasCondition, parseFloatExt, formatAsCurrency, escapeRegExCharacters, getValue, getStrings, generateFormChange, applyFormChanges, findComponent, getEmptyValue, isComponentDataEmpty, isSelectResourceWithObjectValue, compareSelectResourceWithObjectTypeValues, getItemTemplateKeys } = core_1.Utils;
6
6
  exports.flattenComponents = flattenComponents;
7
7
  exports.guid = guid;
8
8
  exports.uniqueName = uniqueName;
9
- exports.MODEL_TYPES = MODEL_TYPES;
9
+ exports.MODEL_TYPES_OF_KNOWN_COMPONENTS = MODEL_TYPES_OF_KNOWN_COMPONENTS;
10
10
  exports.getModelType = getModelType;
11
- exports.getComponentAbsolutePath = getComponentAbsolutePath;
12
11
  exports.getComponentPath = getComponentPath;
12
+ exports.setComponentScope = setComponentScope;
13
+ exports.resetComponentScope = resetComponentScope;
13
14
  exports.isComponentNestedDataType = isComponentNestedDataType;
14
15
  exports.componentPath = componentPath;
15
- exports.componentChildPath = componentChildPath;
16
+ exports.getComponentPaths = getComponentPaths;
17
+ exports.componentMatches = componentMatches;
18
+ exports.getBestMatch = getBestMatch;
19
+ exports.getComponentFromPath = getComponentFromPath;
20
+ exports.getComponentValue = getComponentValue;
21
+ exports.findComponents = findComponents;
16
22
  exports.eachComponentDataAsync = eachComponentDataAsync;
17
23
  exports.eachComponentData = eachComponentData;
18
24
  exports.getComponentKey = getComponentKey;
@@ -42,14 +48,3 @@ exports.isComponentDataEmpty = isComponentDataEmpty;
42
48
  exports.isSelectResourceWithObjectValue = isSelectResourceWithObjectValue;
43
49
  exports.compareSelectResourceWithObjectTypeValues = compareSelectResourceWithObjectTypeValues;
44
50
  exports.getItemTemplateKeys = getItemTemplateKeys;
45
- /**
46
- * Deprecated version of findComponents. Renamed to searchComponents.
47
- * @param {import('@formio/core').Component[]} components - The components to find components within.
48
- * @param {object} query - The query to use when searching for the components.
49
- * @returns {import('@formio/core').Component[]} - The result of the component that is found.
50
- */
51
- function findComponents(components, query) {
52
- console.warn('formio.js/utils findComponents is deprecated. Use searchComponents instead.');
53
- return searchComponents(components, query);
54
- }
55
- exports.findComponents = findComponents;
@@ -79,7 +79,12 @@ class I18n {
79
79
  this.languages[language] = strings;
80
80
  }
81
81
  t(text, ...args) {
82
+ var _a;
82
83
  if (this.currentLanguage[text]) {
84
+ const customTranslationFieldName = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.field;
85
+ if (customTranslationFieldName && this.currentLanguage[customTranslationFieldName]) {
86
+ args[0].field = this.currentLanguage[customTranslationFieldName];
87
+ }
83
88
  return utils_1.Evaluator.interpolateString(this.currentLanguage[text], ...args);
84
89
  }
85
90
  return utils_1.Evaluator.interpolateString(text, ...args);
@@ -462,10 +462,9 @@ export function getComponentPathWithoutIndicies(path?: string): string;
462
462
  /**
463
463
  * Returns a path to the component which based on its schema
464
464
  * @param {import('@formio/core').Component} component - Component containing link to its parent's schema in the 'parent' property
465
- * @param {string} path - Path to the component
466
465
  * @returns {string} - Path to the component
467
466
  */
468
- export function getComponentPath(component: import('@formio/core').Component, path?: string): string;
467
+ export function getComponentPath(component: import('@formio/core').Component): string;
469
468
  /**
470
469
  * Returns a parent component of the passed component instance skipping all the Layout components
471
470
  * @param {Component} componentInstance - The component to check for the parent.
@@ -51,17 +51,6 @@ json_logic_js_1.default.add_operation('relativeMinDate', (relativeMinDate) => {
51
51
  json_logic_js_1.default.add_operation('relativeMaxDate', (relativeMaxDate) => {
52
52
  return (0, moment_timezone_1.default)().add(relativeMaxDate, 'days').toISOString();
53
53
  });
54
- /**
55
- * Sets the path to the component and parent schema.
56
- * @param {import('@formio/core').Component} component - The component to set the path for.
57
- */
58
- function setPathToComponentAndPerentSchema(component) {
59
- component.path = getComponentPath(component);
60
- const dataParent = getDataParentComponent(component);
61
- if (dataParent && typeof dataParent === 'object') {
62
- dataParent.path = getComponentPath(dataParent);
63
- }
64
- }
65
54
  /**
66
55
  * Evaluate a method.
67
56
  * @param {Function|string|object} func - The function to evaluate.
@@ -262,7 +251,7 @@ function checkSimpleConditional(component, condition, row, data, instance) {
262
251
  const value = getComponentActualValue(path, data, row);
263
252
  const ConditionOperator = conditionOperators_1.default[operator];
264
253
  return ConditionOperator
265
- ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath })
254
+ ? new ConditionOperator().getResult({ value, comparedValue, instance, component, path })
266
255
  : true;
267
256
  });
268
257
  }
@@ -270,7 +259,7 @@ function checkSimpleConditional(component, condition, row, data, instance) {
270
259
  const value = getComponentActualValue(conditionComponentPath, data, row);
271
260
  const СonditionOperator = conditionOperators_1.default[operator];
272
261
  return СonditionOperator
273
- ? new СonditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath })
262
+ ? new СonditionOperator().getResult({ value, comparedValue, instance, component, path: conditionComponentPath })
274
263
  : true;
275
264
  }
276
265
  });
@@ -295,12 +284,12 @@ exports.checkSimpleConditional = checkSimpleConditional;
295
284
  */
296
285
  function getComponentActualValue(compPath, data, row) {
297
286
  let value = null;
298
- if (row) {
299
- value = (0, formUtils_1.getValue)({ data: row }, compPath);
300
- }
301
- if (data && lodash_1.default.isNil(value)) {
287
+ if (data) {
302
288
  value = (0, formUtils_1.getValue)({ data }, compPath);
303
289
  }
290
+ if (row && lodash_1.default.isNil(value)) {
291
+ value = (0, formUtils_1.getValue)({ data: row }, compPath);
292
+ }
304
293
  // FOR-400 - Fix issue where falsey values were being evaluated as show=true
305
294
  if (lodash_1.default.isNil(value) || (lodash_1.default.isObject(value) && lodash_1.default.isEmpty(value))) {
306
295
  value = '';
@@ -367,22 +356,23 @@ exports.checkJsonConditional = checkJsonConditional;
367
356
  * @returns {*} - The contextual row data for the component.
368
357
  */
369
358
  function getRow(component, row, instance, conditional) {
370
- var _a;
359
+ var _a, _b, _c;
371
360
  const condition = conditional || component.conditional;
372
361
  // If no component's instance passed (happens only in 6.x server), calculate its path based on the schema
373
362
  if (!instance) {
374
363
  instance = lodash_1.default.cloneDeep(component);
375
- setPathToComponentAndPerentSchema(instance);
376
364
  }
377
365
  const dataParent = getDataParentComponent(instance);
378
- const parentPath = dataParent ? getComponentPath(dataParent) : null;
379
- const isTriggerCondtionComponentPath = condition.when || !condition.conditions
380
- ? (_a = condition.when) === null || _a === void 0 ? void 0 : _a.startsWith(parentPath)
381
- : lodash_1.default.some(condition.conditions, cond => cond.component.startsWith(parentPath));
382
- if (dataParent && isTriggerCondtionComponentPath) {
383
- const newRow = {};
384
- lodash_1.default.set(newRow, parentPath, row);
385
- row = newRow;
366
+ if (dataParent) {
367
+ const parentPath = (_a = dataParent.paths) === null || _a === void 0 ? void 0 : _a.localDataPath;
368
+ const isTriggerCondtionComponentPath = condition.when || !condition.conditions
369
+ ? (_b = condition.when) === null || _b === void 0 ? void 0 : _b.startsWith((_c = dataParent.paths) === null || _c === void 0 ? void 0 : _c.localPath)
370
+ : lodash_1.default.some(condition.conditions, cond => { var _a; return cond.component.startsWith((_a = dataParent.paths) === null || _a === void 0 ? void 0 : _a.localPath); });
371
+ if (isTriggerCondtionComponentPath) {
372
+ const newRow = {};
373
+ lodash_1.default.set(newRow, parentPath, row);
374
+ row = newRow;
375
+ }
386
376
  }
387
377
  return row;
388
378
  }
@@ -1566,16 +1556,10 @@ exports.getComponentPathWithoutIndicies = getComponentPathWithoutIndicies;
1566
1556
  /**
1567
1557
  * Returns a path to the component which based on its schema
1568
1558
  * @param {import('@formio/core').Component} component - Component containing link to its parent's schema in the 'parent' property
1569
- * @param {string} path - Path to the component
1570
1559
  * @returns {string} - Path to the component
1571
1560
  */
1572
- function getComponentPath(component, path = '') {
1573
- var _a;
1574
- if (!component || !component.key || ((_a = component === null || component === void 0 ? void 0 : component._form) === null || _a === void 0 ? void 0 : _a.display) === 'wizard') { // unlike the Webform, the Wizard has the key and it is a duplicate of the panel key
1575
- return path;
1576
- }
1577
- path = component.isInputComponent || component.input === true ? `${component.key}${path ? '.' : ''}${path}` : path;
1578
- return getComponentPath(component.parent, path);
1561
+ function getComponentPath(component) {
1562
+ return component.paths.localDataPath;
1579
1563
  }
1580
1564
  exports.getComponentPath = getComponentPath;
1581
1565
  /**
@@ -426,7 +426,7 @@ declare class Webform extends NestedDataComponent {
426
426
  */
427
427
  cancel(noconfirm: boolean): boolean;
428
428
  setMetadata(submission: any): void;
429
- submitForm(options?: {}): Promise<any>;
429
+ submitForm(options?: {}, local?: boolean): Promise<any>;
430
430
  setServerErrors(error: any): void;
431
431
  serverErrors: any;
432
432
  executeSubmit(options: any): Promise<object>;
@@ -588,6 +588,7 @@ export default class Webform extends NestedDataComponent {
588
588
  try {
589
589
  // Do not set the form again if it has been already set
590
590
  if (isFormAlreadySet && JSON.stringify(this._form) === JSON.stringify(form)) {
591
+ this.formReadyResolve();
591
592
  return Promise.resolve();
592
593
  }
593
594
  // Create the form.
@@ -595,13 +596,11 @@ export default class Webform extends NestedDataComponent {
595
596
  if (this.onSetForm) {
596
597
  this.onSetForm(_.cloneDeep(this._form), form);
597
598
  }
598
- if (this.parent?.component?.modalEdit) {
599
- return Promise.resolve();
600
- }
601
599
  }
602
600
  catch (err) {
603
601
  console.warn(err);
604
602
  // If provided form is not a valid JSON object, do not set it too
603
+ this.formReadyReject(err);
605
604
  return Promise.resolve();
606
605
  }
607
606
  // Allow the form to provide component overrides.
@@ -850,6 +849,9 @@ export default class Webform extends NestedDataComponent {
850
849
  return changed;
851
850
  }
852
851
  getValue() {
852
+ if (!this._submission) {
853
+ this._submission = {};
854
+ }
853
855
  if (!this._submission.data) {
854
856
  this._submission.data = {};
855
857
  }
@@ -1111,29 +1113,23 @@ export default class Webform extends NestedDataComponent {
1111
1113
  return;
1112
1114
  }
1113
1115
  // Mark any components as invalid if in a custom message.
1116
+ const componentErrors = {};
1114
1117
  errors.forEach((err) => {
1115
- const { components = [] } = err;
1116
- if (err.component) {
1117
- components.push(err.component);
1118
+ const path = err.path || err.context?.path || err.component?.key;
1119
+ if (!componentErrors[path]) {
1120
+ componentErrors[path] = [];
1118
1121
  }
1119
- if (err.path) {
1120
- components.push(err.path);
1121
- }
1122
- components.forEach((path) => {
1123
- const originalPath = getStringFromComponentPath(path);
1124
- const component = this.getComponent(path, _.identity, originalPath);
1125
- if (err.fromServer) {
1126
- if (component.serverErrors) {
1127
- component.serverErrors.push(err);
1128
- }
1129
- else {
1130
- component.serverErrors = [err];
1131
- }
1132
- }
1133
- const components = _.compact(Array.isArray(component) ? component : [component]);
1134
- components.forEach((component) => component.setCustomValidity(err.message, true));
1135
- });
1122
+ componentErrors[path].push(err);
1136
1123
  });
1124
+ // Iterate through all of our component errors and apply them to the components.
1125
+ for (let path in componentErrors) {
1126
+ const component = this.getComponent(path);
1127
+ const errors = componentErrors[path];
1128
+ if (component) {
1129
+ component.serverErrors = errors.filter((err) => err.fromServer);
1130
+ component.setCustomValidity(errors, true);
1131
+ }
1132
+ }
1137
1133
  const displayedErrors = [];
1138
1134
  if (errors.length) {
1139
1135
  errors = _.uniqBy(errors, (error) => [error.message, error.component?.id, error.context?.path].join());
@@ -1326,7 +1322,7 @@ export default class Webform extends NestedDataComponent {
1326
1322
  onLine: navigator.onLine,
1327
1323
  });
1328
1324
  }
1329
- submitForm(options = {}) {
1325
+ submitForm(options = {}, local = false) {
1330
1326
  this.clearServerErrors();
1331
1327
  return new Promise((resolve, reject) => {
1332
1328
  // Read-only forms should never submit.
@@ -1351,6 +1347,7 @@ export default class Webform extends NestedDataComponent {
1351
1347
  return reject("Invalid Submission");
1352
1348
  }
1353
1349
  const errors = this.validate(submission.data, {
1350
+ local,
1354
1351
  dirty: true,
1355
1352
  silentCheck: false,
1356
1353
  process: "submit",
@@ -1366,11 +1363,11 @@ export default class Webform extends NestedDataComponent {
1366
1363
  }
1367
1364
  this.everyComponent((comp) => {
1368
1365
  if (submission._vnote && comp.type === "form" && comp.component.reference) {
1369
- _.get(submission.data, comp.path, {})._vnote = submission._vnote;
1366
+ _.get(submission.data, local ? comp.paths?.localDataPath : comp.path, {})._vnote = submission._vnote;
1370
1367
  }
1371
1368
  const { persistent } = comp.component;
1372
1369
  if (persistent === "client-only") {
1373
- _.unset(submission.data, comp.path);
1370
+ _.unset(submission.data, local ? comp.paths?.localDataPath : comp.path);
1374
1371
  }
1375
1372
  });
1376
1373
  this.hook("customValidation", { ...submission, component: options.component }, (err) => {
@@ -1536,7 +1533,7 @@ export default class Webform extends NestedDataComponent {
1536
1533
  return;
1537
1534
  }
1538
1535
  const captchaComponent = [];
1539
- eachComponent(this.components, (component) => {
1536
+ this.eachComponent((component) => {
1540
1537
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1541
1538
  captchaComponent.push(component);
1542
1539
  }
@@ -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
  }
@@ -898,13 +885,16 @@ export default class WebformBuilder extends Component {
898
885
  keyboardActionsEnabled = keyboardActionsEnabled === 'true';
899
886
  }
900
887
  this.keyboardActionsEnabled = keyboardActionsEnabled;
901
- const isSubmitButton = (comp) => {
902
- return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
903
- };
904
- const isShowSubmitButton = !this.options.noDefaultSubmitButton
905
- && (!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);
906
896
  // Ensure there is at least a submit button.
907
- if (isShowSubmitButton) {
897
+ if (!noDefaultSubmitButton && shouldAddSubmitButton) {
908
898
  form.components.push({
909
899
  type: 'button',
910
900
  label: 'Submit',
@@ -1053,6 +1043,7 @@ export default class WebformBuilder extends Component {
1053
1043
  'conditional',
1054
1044
  'customConditional',
1055
1045
  'id',
1046
+ 'logic',
1056
1047
  'fields.day.required',
1057
1048
  'fields.month.required',
1058
1049
  'fields.year.required',
@@ -1078,6 +1069,12 @@ export default class WebformBuilder extends Component {
1078
1069
  parentComponent.tabs[tabIndex].splice(index, 1, newComp);
1079
1070
  newComp.checkValidity = () => true;
1080
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
+ }
1081
1078
  }
1082
1079
  }
1083
1080
  else {
@@ -1088,6 +1085,7 @@ export default class WebformBuilder extends Component {
1088
1085
  path.unshift(component.key);
1089
1086
  dataPath = getStringFromComponentPath(path);
1090
1087
  }
1088
+ this.preview.defaultChanged = true;
1091
1089
  _.set(this.preview._data, dataPath, changed.value);
1092
1090
  _.set(this.webform._data, dataPath, changed.value);
1093
1091
  }
@@ -1098,20 +1096,12 @@ export default class WebformBuilder extends Component {
1098
1096
  findRepeatablePaths() {
1099
1097
  const repeatablePaths = [];
1100
1098
  const keys = new Map();
1101
- eachComponent(this.form.components, (comp, path) => {
1102
- if (!comp.key) {
1103
- return;
1104
- }
1105
- if (keys.has(comp.key)) {
1106
- if (keys.get(comp.key).includes(path)) {
1107
- repeatablePaths.push(path);
1108
- }
1109
- else {
1110
- keys.set(comp.key, [...keys.get(comp.key), path]);
1111
- }
1099
+ eachComponent(this.form.components, (comp, path, components, parent, paths) => {
1100
+ if (keys.has(paths.dataPath)) {
1101
+ repeatablePaths.push(paths.dataPath);
1112
1102
  }
1113
1103
  else {
1114
- keys.set(comp.key, [path]);
1104
+ keys.set(paths.dataPath, true);
1115
1105
  }
1116
1106
  }, true);
1117
1107
  return repeatablePaths;
@@ -1172,6 +1162,7 @@ export default class WebformBuilder extends Component {
1172
1162
  }
1173
1163
  const rebuild = parentComponent.rebuild() || Promise.resolve();
1174
1164
  return rebuild.then(() => {
1165
+ parentComponent.resetValue();
1175
1166
  const schema = parentContainer ? parentContainer[index] : (comp ? comp.schema : []);
1176
1167
  this.emitSaveComponentEvent(schema, originalComp, parentComponent.schema, path, index, isNew, originalComponentSchema);
1177
1168
  this.emit('change', this.form);
@@ -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
@@ -369,7 +369,7 @@ export default class Wizard extends Webform {
369
369
  }
370
370
  attachHeader() {
371
371
  const isAllowPrevious = this.isAllowPrevious();
372
- this.attachTooltips(this.refs[`${this.wizardKey}-tooltip`], this.currentPanel.tooltip);
372
+ this.attachTooltips(this.refs[`${this.wizardKey}-tooltip`], this.currentPanel?.tooltip);
373
373
  if (this.isBreadcrumbClickable() || isAllowPrevious) {
374
374
  this.refs[`${this.wizardKey}-link`]?.forEach((link, index) => {
375
375
  if (!isAllowPrevious || index <= this.enabledIndex) {
@@ -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,12 +711,13 @@ 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 = {}) {
718
+ const components = this.currentPage?.components.map((component) => component.component);
713
719
  // 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);
720
+ return this.currentPage?.parent.validateComponents(components, this.root.data, flags);
715
721
  }
716
722
  emitPrevPage() {
717
723
  this.emit('prevPage', { page: this.page, submission: this.submission });
@@ -852,7 +858,8 @@ export default class Wizard extends Webform {
852
858
  }
853
859
  onChange(flags, changed, modified, changes) {
854
860
  super.onChange(flags, changed, modified, changes);
855
- const errors = this.validate(this.localData, { dirty: false });
861
+ // The onChange loop doesn't need all components for wizards
862
+ const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
856
863
  if (this.alert) {
857
864
  this.showErrors(errors, true, true);
858
865
  }
@@ -884,12 +891,6 @@ export default class Wizard extends Webform {
884
891
  this.redraw();
885
892
  }
886
893
  }
887
- redraw() {
888
- if (this.parent?.component?.modalEdit) {
889
- return this.parent.redraw();
890
- }
891
- return super.redraw();
892
- }
893
894
  rebuild() {
894
895
  const currentPage = this.page;
895
896
  const setCurrentPage = () => this.setPage(currentPage);
@@ -906,21 +907,7 @@ export default class Wizard extends Webform {
906
907
  return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, currentPageOnly, childErrors) && check, true);
907
908
  }
908
909
  get errors() {
909
- if (!this.isLastPage()) {
910
- return this.currentPage.errors;
911
- }
912
- return super.errors;
913
- }
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);
910
+ return !this.isLastPage() && !this.submitted ? this.currentPage.errors : super.errors;
924
911
  }
925
912
  focusOnComponent(key) {
926
913
  const component = this.getComponent(key);
@@ -256,13 +256,6 @@ export default class Components {
256
256
  static setComponents(comps: any): void;
257
257
  static addComponent(name: any, comp: any): void;
258
258
  static setComponent(name: any, comp: any): void;
259
- /**
260
- * Return a path of component's value.
261
- * @param {Component} component - The component instance.
262
- * @returns {string} - The component's value path.
263
- */
264
- static getComponentPath(component: Component): string;
265
259
  static create(component: any, options: any, data: any): any;
266
260
  }
267
261
  import BaseEditForm from './_classes/component/Component.form';
268
- import Component from './_classes/component/Component';