@formio/js 5.0.0 → 5.1.0-rc.1
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.
- package/dist/formio.embed.js +1 -1
- package/dist/formio.embed.min.js +1 -1
- package/dist/formio.embed.min.js.LICENSE.txt +1 -1
- package/dist/formio.form.js +120 -109
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +3 -3
- package/dist/formio.full.js +121 -110
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +3 -3
- package/dist/formio.js +3011 -281
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +14 -2
- package/dist/formio.utils.js +55 -44
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +3 -3
- package/lib/cjs/Webform.d.ts +8 -1
- package/lib/cjs/Webform.js +40 -32
- package/lib/cjs/WebformBuilder.js +4 -12
- package/lib/cjs/Wizard.js +4 -11
- package/lib/cjs/components/Components.d.ts +0 -7
- package/lib/cjs/components/Components.js +1 -33
- package/lib/cjs/components/_classes/component/Component.d.ts +37 -7
- package/lib/cjs/components/_classes/component/Component.js +70 -26
- package/lib/cjs/components/_classes/componentModal/ComponentModal.d.ts +1 -0
- package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -0
- package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +4 -19
- package/lib/cjs/components/_classes/nested/NestedComponent.js +38 -53
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -1
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +7 -44
- package/lib/cjs/components/datagrid/DataGrid.d.ts +0 -1
- package/lib/cjs/components/datagrid/DataGrid.js +1 -45
- package/lib/cjs/components/datamap/DataMap.js +1 -2
- package/lib/cjs/components/editgrid/EditGrid.js +6 -6
- package/lib/cjs/components/form/Form.d.ts +8 -3
- package/lib/cjs/components/form/Form.js +26 -25
- package/lib/cjs/components/selectboxes/SelectBoxes.js +0 -1
- package/lib/cjs/components/signature/Signature.d.ts +0 -1
- package/lib/cjs/components/signature/Signature.js +1 -1
- package/lib/cjs/utils/conditionOperators/DateGreaterThan.js +2 -2
- package/lib/cjs/utils/conditionOperators/IsEmptyValue.d.ts +2 -2
- package/lib/cjs/utils/conditionOperators/IsEmptyValue.js +2 -2
- package/lib/cjs/utils/conditionOperators/IsEqualTo.d.ts +2 -2
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +2 -2
- package/lib/cjs/utils/formUtils.d.ts +25 -14
- package/lib/cjs/utils/formUtils.js +11 -16
- package/lib/cjs/utils/utils.d.ts +1 -3
- package/lib/cjs/utils/utils.js +19 -35
- package/lib/mjs/Webform.d.ts +8 -1
- package/lib/mjs/Webform.js +37 -31
- package/lib/mjs/WebformBuilder.js +4 -12
- package/lib/mjs/Wizard.js +2 -8
- package/lib/mjs/components/Components.d.ts +0 -7
- package/lib/mjs/components/Components.js +1 -32
- package/lib/mjs/components/_classes/component/Component.d.ts +37 -7
- package/lib/mjs/components/_classes/component/Component.js +80 -27
- package/lib/mjs/components/_classes/componentModal/ComponentModal.d.ts +1 -0
- package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -0
- package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +4 -19
- package/lib/mjs/components/_classes/nested/NestedComponent.js +39 -54
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -1
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +8 -43
- package/lib/mjs/components/datagrid/DataGrid.d.ts +0 -1
- package/lib/mjs/components/datagrid/DataGrid.js +1 -45
- package/lib/mjs/components/datamap/DataMap.js +1 -2
- package/lib/mjs/components/editgrid/EditGrid.js +9 -6
- package/lib/mjs/components/form/Form.d.ts +8 -3
- package/lib/mjs/components/form/Form.js +27 -25
- package/lib/mjs/components/selectboxes/SelectBoxes.js +0 -1
- package/lib/mjs/components/signature/Signature.d.ts +0 -1
- package/lib/mjs/components/signature/Signature.js +1 -1
- package/lib/mjs/utils/conditionOperators/DateGreaterThan.js +2 -2
- package/lib/mjs/utils/conditionOperators/IsEmptyValue.d.ts +2 -2
- package/lib/mjs/utils/conditionOperators/IsEmptyValue.js +2 -2
- package/lib/mjs/utils/conditionOperators/IsEqualTo.d.ts +2 -2
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +2 -2
- package/lib/mjs/utils/formUtils.d.ts +25 -14
- package/lib/mjs/utils/formUtils.js +2 -12
- package/lib/mjs/utils/utils.d.ts +1 -3
- package/lib/mjs/utils/utils.js +18 -33
- package/package.json +4 -4
@@ -15,11 +15,11 @@ class IsEmptyValue extends ConditionOperator_1.default {
|
|
15
15
|
static get requireValue() {
|
16
16
|
return false;
|
17
17
|
}
|
18
|
-
execute({ value, instance,
|
18
|
+
execute({ value, instance, path }) {
|
19
19
|
var _a;
|
20
20
|
const isEmptyValue = lodash_1.default.isEmpty(lodash_1.default.isNumber(value) ? String(value) : value);
|
21
21
|
if ((_a = instance === null || instance === void 0 ? void 0 : instance.root) === null || _a === void 0 ? void 0 : _a.getComponent) {
|
22
|
-
const conditionTriggerComponent = instance.root.getComponent(
|
22
|
+
const conditionTriggerComponent = instance.root.getComponent(path);
|
23
23
|
return (conditionTriggerComponent === null || conditionTriggerComponent === void 0 ? void 0 : conditionTriggerComponent.isEmpty) ? conditionTriggerComponent.isEmpty() : isEmptyValue;
|
24
24
|
}
|
25
25
|
return isEmptyValue;
|
@@ -1,9 +1,9 @@
|
|
1
1
|
export default class IsEqualTo extends ConditionOperator {
|
2
|
-
execute({ value, comparedValue, instance,
|
2
|
+
execute({ value, comparedValue, instance, path }: {
|
3
3
|
value: any;
|
4
4
|
comparedValue: any;
|
5
5
|
instance: any;
|
6
|
-
|
6
|
+
path: any;
|
7
7
|
}): any;
|
8
8
|
}
|
9
9
|
import ConditionOperator from './ConditionOperator';
|
@@ -13,7 +13,7 @@ class IsEqualTo extends ConditionOperator_1.default {
|
|
13
13
|
static get displayedName() {
|
14
14
|
return 'Is Equal To';
|
15
15
|
}
|
16
|
-
execute({ value, comparedValue, instance,
|
16
|
+
execute({ value, comparedValue, instance, path }) {
|
17
17
|
var _a, _b;
|
18
18
|
if ((value || value === false) && comparedValue && typeof value !== typeof comparedValue && lodash_1.default.isString(comparedValue)) {
|
19
19
|
try {
|
@@ -23,7 +23,7 @@ class IsEqualTo extends ConditionOperator_1.default {
|
|
23
23
|
catch (e) { }
|
24
24
|
}
|
25
25
|
if ((_a = instance === null || instance === void 0 ? void 0 : instance.root) === null || _a === void 0 ? void 0 : _a.getComponent) {
|
26
|
-
const conditionTriggerComponent = instance.root.getComponent(
|
26
|
+
const conditionTriggerComponent = instance.root.getComponent(path);
|
27
27
|
if (conditionTriggerComponent
|
28
28
|
&& (0, utils_1.isSelectResourceWithObjectValue)(conditionTriggerComponent.component)
|
29
29
|
&& ((_b = conditionTriggerComponent.component) === null || _b === void 0 ? void 0 : _b.template)) {
|
@@ -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
|
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
|
14
|
-
export const
|
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
|
18
|
-
export const
|
19
|
-
export const
|
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:
|
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.
|
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,
|
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.
|
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.
|
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;
|
package/lib/cjs/utils/utils.d.ts
CHANGED
@@ -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
|
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.
|
@@ -515,7 +514,6 @@ export namespace componentValueTypes {
|
|
515
514
|
let any: string;
|
516
515
|
}
|
517
516
|
export function interpolateErrors(component: Component, errors: FieldError[], interpolateFn: Function): [];
|
518
|
-
import jsonLogic from 'json-logic-js';
|
519
517
|
import ConditionOperators from './conditionOperators';
|
520
518
|
import { Evaluator } from './Evaluator';
|
521
519
|
export const interpolate: typeof Evaluator.interpolate;
|
package/lib/cjs/utils/utils.js
CHANGED
@@ -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,
|
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 (
|
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
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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
|
1573
|
-
|
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
|
/**
|
package/lib/mjs/Webform.d.ts
CHANGED
@@ -330,6 +330,13 @@ declare class Webform extends NestedDataComponent {
|
|
330
330
|
* @returns {object} - The submission object.
|
331
331
|
*/
|
332
332
|
get submission(): object;
|
333
|
+
/**
|
334
|
+
* Sets the submission value
|
335
|
+
* @param {object|null|undefined} submission - The submission to set.
|
336
|
+
* @param {object|null|undefined} flags - Any flags to apply when setting the submission.
|
337
|
+
* @return {void}
|
338
|
+
*/
|
339
|
+
onSetSubmission(submission: object | null | undefined, flags?: object | null | undefined): void;
|
333
340
|
/**
|
334
341
|
* Sets a submission and returns the promise when it is ready.
|
335
342
|
* @param {any} submission - The submission to set.
|
@@ -419,7 +426,7 @@ declare class Webform extends NestedDataComponent {
|
|
419
426
|
*/
|
420
427
|
cancel(noconfirm: boolean): boolean;
|
421
428
|
setMetadata(submission: any): void;
|
422
|
-
submitForm(options?: {}): Promise<any>;
|
429
|
+
submitForm(options?: {}, local?: boolean): Promise<any>;
|
423
430
|
setServerErrors(error: any): void;
|
424
431
|
serverErrors: any;
|
425
432
|
executeSubmit(options: any): Promise<object>;
|
package/lib/mjs/Webform.js
CHANGED
@@ -590,6 +590,7 @@ export default class Webform extends NestedDataComponent {
|
|
590
590
|
try {
|
591
591
|
// Do not set the form again if it has been already set
|
592
592
|
if (isFormAlreadySet && JSON.stringify(this._form) === JSON.stringify(form)) {
|
593
|
+
this.formReadyResolve();
|
593
594
|
return Promise.resolve();
|
594
595
|
}
|
595
596
|
// Create the form.
|
@@ -597,13 +598,11 @@ export default class Webform extends NestedDataComponent {
|
|
597
598
|
if (this.onSetForm) {
|
598
599
|
this.onSetForm(_.cloneDeep(this._form), form);
|
599
600
|
}
|
600
|
-
if (this.parent?.component?.modalEdit) {
|
601
|
-
return Promise.resolve();
|
602
|
-
}
|
603
601
|
}
|
604
602
|
catch (err) {
|
605
603
|
console.warn(err);
|
606
604
|
// If provided form is not a valid JSON object, do not set it too
|
605
|
+
this.formReadyReject(err);
|
607
606
|
return Promise.resolve();
|
608
607
|
}
|
609
608
|
// Allow the form to provide component overrides.
|
@@ -702,6 +701,18 @@ export default class Webform extends NestedDataComponent {
|
|
702
701
|
set submission(submission) {
|
703
702
|
this.setSubmission(submission);
|
704
703
|
}
|
704
|
+
/**
|
705
|
+
* Sets the submission value
|
706
|
+
* @param {object|null|undefined} submission - The submission to set.
|
707
|
+
* @param {object|null|undefined} flags - Any flags to apply when setting the submission.
|
708
|
+
* @return {void}
|
709
|
+
*/
|
710
|
+
onSetSubmission(submission, flags = {}) {
|
711
|
+
this.submissionSet = true;
|
712
|
+
this.triggerChange(flags);
|
713
|
+
this.emit('beforeSetSubmission', submission);
|
714
|
+
this.setValue(submission, flags);
|
715
|
+
}
|
705
716
|
/**
|
706
717
|
* Sets a submission and returns the promise when it is ready.
|
707
718
|
* @param {any} submission - The submission to set.
|
@@ -721,10 +732,7 @@ export default class Webform extends NestedDataComponent {
|
|
721
732
|
...resolveFlags,
|
722
733
|
};
|
723
734
|
}
|
724
|
-
this.
|
725
|
-
this.triggerChange(flags);
|
726
|
-
this.emit("beforeSetSubmission", submission);
|
727
|
-
this.setValue(submission, flags);
|
735
|
+
this.onSetSubmission(submission, flags);
|
728
736
|
return this.submissionReadyResolve(submission);
|
729
737
|
}, (err) => this.submissionReadyReject(err))
|
730
738
|
.catch((err) => this.submissionReadyReject(err)));
|
@@ -843,6 +851,9 @@ export default class Webform extends NestedDataComponent {
|
|
843
851
|
return changed;
|
844
852
|
}
|
845
853
|
getValue() {
|
854
|
+
if (!this._submission) {
|
855
|
+
this._submission = {};
|
856
|
+
}
|
846
857
|
if (!this._submission.data) {
|
847
858
|
this._submission.data = {};
|
848
859
|
}
|
@@ -1102,29 +1113,23 @@ export default class Webform extends NestedDataComponent {
|
|
1102
1113
|
return;
|
1103
1114
|
}
|
1104
1115
|
// Mark any components as invalid if in a custom message.
|
1116
|
+
const componentErrors = {};
|
1105
1117
|
errors.forEach((err) => {
|
1106
|
-
const
|
1107
|
-
if (
|
1108
|
-
|
1109
|
-
}
|
1110
|
-
if (err.path) {
|
1111
|
-
components.push(err.path);
|
1118
|
+
const path = err.path || err.context?.path || err.component?.key;
|
1119
|
+
if (!componentErrors[path]) {
|
1120
|
+
componentErrors[path] = [];
|
1112
1121
|
}
|
1113
|
-
|
1114
|
-
const originalPath = getStringFromComponentPath(path);
|
1115
|
-
const component = this.getComponent(path, _.identity, originalPath);
|
1116
|
-
if (err.fromServer) {
|
1117
|
-
if (component.serverErrors) {
|
1118
|
-
component.serverErrors.push(err);
|
1119
|
-
}
|
1120
|
-
else {
|
1121
|
-
component.serverErrors = [err];
|
1122
|
-
}
|
1123
|
-
}
|
1124
|
-
const components = _.compact(Array.isArray(component) ? component : [component]);
|
1125
|
-
components.forEach((component) => component.setCustomValidity(err.message, true));
|
1126
|
-
});
|
1122
|
+
componentErrors[path].push(err);
|
1127
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
|
+
}
|
1128
1133
|
const displayedErrors = [];
|
1129
1134
|
if (errors.length) {
|
1130
1135
|
errors = _.uniqBy(errors, (error) => [error.message, error.component?.id, error.context?.path].join());
|
@@ -1317,7 +1322,7 @@ export default class Webform extends NestedDataComponent {
|
|
1317
1322
|
onLine: navigator.onLine,
|
1318
1323
|
});
|
1319
1324
|
}
|
1320
|
-
submitForm(options = {}) {
|
1325
|
+
submitForm(options = {}, local = false) {
|
1321
1326
|
this.clearServerErrors();
|
1322
1327
|
return new Promise((resolve, reject) => {
|
1323
1328
|
// Read-only forms should never submit.
|
@@ -1342,6 +1347,7 @@ export default class Webform extends NestedDataComponent {
|
|
1342
1347
|
return reject("Invalid Submission");
|
1343
1348
|
}
|
1344
1349
|
const errors = this.validate(submission.data, {
|
1350
|
+
local,
|
1345
1351
|
dirty: true,
|
1346
1352
|
silentCheck: false,
|
1347
1353
|
process: "submit",
|
@@ -1357,11 +1363,11 @@ export default class Webform extends NestedDataComponent {
|
|
1357
1363
|
}
|
1358
1364
|
this.everyComponent((comp) => {
|
1359
1365
|
if (submission._vnote && comp.type === "form" && comp.component.reference) {
|
1360
|
-
_.get(submission.data, comp.path, {})._vnote = submission._vnote;
|
1366
|
+
_.get(submission.data, local ? comp.paths?.localDataPath : comp.path, {})._vnote = submission._vnote;
|
1361
1367
|
}
|
1362
1368
|
const { persistent } = comp.component;
|
1363
1369
|
if (persistent === "client-only") {
|
1364
|
-
_.unset(submission.data, comp.path);
|
1370
|
+
_.unset(submission.data, local ? comp.paths?.localDataPath : comp.path);
|
1365
1371
|
}
|
1366
1372
|
});
|
1367
1373
|
this.hook("customValidation", { ...submission, component: options.component }, (err) => {
|
@@ -1527,7 +1533,7 @@ export default class Webform extends NestedDataComponent {
|
|
1527
1533
|
return;
|
1528
1534
|
}
|
1529
1535
|
const captchaComponent = [];
|
1530
|
-
|
1536
|
+
this.eachComponent((component) => {
|
1531
1537
|
if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
|
1532
1538
|
captchaComponent.push(component);
|
1533
1539
|
}
|
@@ -1108,20 +1108,12 @@ export default class WebformBuilder extends Component {
|
|
1108
1108
|
findRepeatablePaths() {
|
1109
1109
|
const repeatablePaths = [];
|
1110
1110
|
const keys = new Map();
|
1111
|
-
eachComponent(this.form.components, (comp, path) => {
|
1112
|
-
if (
|
1113
|
-
|
1114
|
-
}
|
1115
|
-
if (keys.has(comp.key)) {
|
1116
|
-
if (keys.get(comp.key).includes(path)) {
|
1117
|
-
repeatablePaths.push(path);
|
1118
|
-
}
|
1119
|
-
else {
|
1120
|
-
keys.set(comp.key, [...keys.get(comp.key), path]);
|
1121
|
-
}
|
1111
|
+
eachComponent(this.form.components, (comp, path, components, parent, paths) => {
|
1112
|
+
if (keys.has(paths.dataPath)) {
|
1113
|
+
repeatablePaths.push(paths.dataPath);
|
1122
1114
|
}
|
1123
1115
|
else {
|
1124
|
-
keys.set(
|
1116
|
+
keys.set(paths.dataPath, true);
|
1125
1117
|
}
|
1126
1118
|
}, true);
|
1127
1119
|
return repeatablePaths;
|
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
|
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) {
|
@@ -717,7 +717,7 @@ export default class Wizard extends Webform {
|
|
717
717
|
validateCurrentPage(flags = {}) {
|
718
718
|
const components = this.currentPage?.components.map((component) => component.component);
|
719
719
|
// Accessing the parent ensures the right instance (whether it's the parent Wizard or a nested Wizard) performs its validation
|
720
|
-
return this.currentPage?.parent.validateComponents(components, this.
|
720
|
+
return this.currentPage?.parent.validateComponents(components, this.root.data, flags);
|
721
721
|
}
|
722
722
|
emitPrevPage() {
|
723
723
|
this.emit('prevPage', { page: this.page, submission: this.submission });
|
@@ -891,12 +891,6 @@ export default class Wizard extends Webform {
|
|
891
891
|
this.redraw();
|
892
892
|
}
|
893
893
|
}
|
894
|
-
redraw() {
|
895
|
-
if (this.parent?.component?.modalEdit) {
|
896
|
-
return this.parent.redraw();
|
897
|
-
}
|
898
|
-
return super.redraw();
|
899
|
-
}
|
900
894
|
rebuild() {
|
901
895
|
const currentPage = this.page;
|
902
896
|
const setCurrentPage = () => this.setPage(currentPage);
|
@@ -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';
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import Component from './_classes/component/Component';
|
2
2
|
import EditFormUtils from './_classes/component/editForm/utils';
|
3
3
|
import BaseEditForm from './_classes/component/Component.form';
|
4
|
-
import { getComponentKey, getModelType } from '../utils/utils';
|
5
4
|
import _ from 'lodash';
|
6
5
|
export default class Components {
|
7
6
|
static _editFormUtils = EditFormUtils;
|
@@ -46,34 +45,6 @@ export default class Components {
|
|
46
45
|
static setComponent(name, comp) {
|
47
46
|
Components.components[name] = comp;
|
48
47
|
}
|
49
|
-
/**
|
50
|
-
* Return a path of component's value.
|
51
|
-
* @param {Component} component - The component instance.
|
52
|
-
* @returns {string} - The component's value path.
|
53
|
-
*/
|
54
|
-
static getComponentPath(component) {
|
55
|
-
let path = '';
|
56
|
-
const componentKey = getComponentKey(component.component);
|
57
|
-
if (componentKey) {
|
58
|
-
let thisPath = component.options?.parent || component;
|
59
|
-
while (thisPath && !thisPath.allowData && thisPath.parent) {
|
60
|
-
thisPath = thisPath.parent;
|
61
|
-
}
|
62
|
-
// TODO: any component that is nested in e.g. a Data Grid or an Edit Grid is going to receive a row prop; the problem
|
63
|
-
// is that options.row is passed to each further nested component, which results in erroneous paths like
|
64
|
-
// `editGrid[0].container[0].textField` rather than `editGrid[0].container.textField`. This should be adapted for other
|
65
|
-
// components with a tree-like data model
|
66
|
-
const rowIndex = component.row;
|
67
|
-
const rowIndexPath = rowIndex && !['container'].includes(thisPath.component.type) ? `[${Number.parseInt(rowIndex)}]` : '';
|
68
|
-
path = `${thisPath.path}${rowIndexPath}.`;
|
69
|
-
if (rowIndexPath && getModelType(thisPath) === 'nestedDataArray') {
|
70
|
-
path = `${path}data.`;
|
71
|
-
}
|
72
|
-
path += componentKey;
|
73
|
-
return _.trim(path, '.');
|
74
|
-
}
|
75
|
-
return path;
|
76
|
-
}
|
77
48
|
static create(component, options, data) {
|
78
49
|
let comp = null;
|
79
50
|
if (component.type && Components.components.hasOwnProperty(component.type)) {
|
@@ -98,9 +69,7 @@ export default class Components {
|
|
98
69
|
else {
|
99
70
|
comp = new Component(component, options, data);
|
100
71
|
}
|
101
|
-
|
102
|
-
if (path) {
|
103
|
-
comp.path = path;
|
72
|
+
if (comp.path) {
|
104
73
|
comp.componentsMap[comp.path] = comp;
|
105
74
|
}
|
106
75
|
return comp;
|