@sprucelabs/spruce-form-utils 10.2.79 → 10.2.80
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.
|
@@ -23,14 +23,17 @@ const formCompletionCalculator = {
|
|
|
23
23
|
calculate(pages, values) {
|
|
24
24
|
var _a, _b, _c, _d;
|
|
25
25
|
validateOptions(pages, values);
|
|
26
|
+
const requiredFields = [];
|
|
26
27
|
let totalFields = 0;
|
|
27
28
|
for (const page of pages) {
|
|
28
29
|
const fields = (_a = page.schema.fields) !== null && _a !== void 0 ? _a : {};
|
|
29
30
|
for (const section of page.sections) {
|
|
30
31
|
for (const field of (_b = section.fields) !== null && _b !== void 0 ? _b : []) {
|
|
31
|
-
const
|
|
32
|
+
const fieldKey = (_c = field.name) !== null && _c !== void 0 ? _c : field;
|
|
33
|
+
const f = (_d = fields[fieldKey]) !== null && _d !== void 0 ? _d : {};
|
|
32
34
|
if (f.isRequired) {
|
|
33
35
|
totalFields++;
|
|
36
|
+
requiredFields.push(fieldKey);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -40,7 +43,9 @@ const formCompletionCalculator = {
|
|
|
40
43
|
}
|
|
41
44
|
let totalAnswered = 0;
|
|
42
45
|
for (const value of values) {
|
|
43
|
-
totalAnswered += Object.keys(value !== null && value !== void 0 ? value : {}).filter((k) =>
|
|
46
|
+
totalAnswered += Object.keys(value !== null && value !== void 0 ? value : {}).filter((k) => {
|
|
47
|
+
return !!value[k] && requiredFields.indexOf(k) !== -1;
|
|
48
|
+
}).length;
|
|
44
49
|
}
|
|
45
50
|
return parseFloat((totalAnswered / totalFields).toFixed(2));
|
|
46
51
|
},
|
|
@@ -25,14 +25,17 @@ const formCompletionCalculator = {
|
|
|
25
25
|
calculate(pages, values) {
|
|
26
26
|
var _a, _b, _c, _d;
|
|
27
27
|
validateOptions(pages, values);
|
|
28
|
+
const requiredFields = [];
|
|
28
29
|
let totalFields = 0;
|
|
29
30
|
for (const page of pages) {
|
|
30
31
|
const fields = (_a = page.schema.fields) !== null && _a !== void 0 ? _a : {};
|
|
31
32
|
for (const section of page.sections) {
|
|
32
33
|
for (const field of (_b = section.fields) !== null && _b !== void 0 ? _b : []) {
|
|
33
|
-
const
|
|
34
|
+
const fieldKey = (_c = field.name) !== null && _c !== void 0 ? _c : field;
|
|
35
|
+
const f = (_d = fields[fieldKey]) !== null && _d !== void 0 ? _d : {};
|
|
34
36
|
if (f.isRequired) {
|
|
35
37
|
totalFields++;
|
|
38
|
+
requiredFields.push(fieldKey);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -42,7 +45,9 @@ const formCompletionCalculator = {
|
|
|
42
45
|
}
|
|
43
46
|
let totalAnswered = 0;
|
|
44
47
|
for (const value of values) {
|
|
45
|
-
totalAnswered += Object.keys(value !== null && value !== void 0 ? value : {}).filter((k) =>
|
|
48
|
+
totalAnswered += Object.keys(value !== null && value !== void 0 ? value : {}).filter((k) => {
|
|
49
|
+
return !!value[k] && requiredFields.indexOf(k) !== -1;
|
|
50
|
+
}).length;
|
|
46
51
|
}
|
|
47
52
|
return parseFloat((totalAnswered / totalFields).toFixed(2));
|
|
48
53
|
},
|