formanitor 0.0.6 → 0.0.8
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/index.cjs +14 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -13
- package/dist/index.d.ts +10 -13
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -371,7 +371,20 @@ var FormStore = class {
|
|
|
371
371
|
this.schema.computations.forEach((comp) => {
|
|
372
372
|
if (comp.type === "sum") {
|
|
373
373
|
const sum = comp.fields.reduce((acc, fieldId) => {
|
|
374
|
-
const
|
|
374
|
+
const raw = this.state.values[fieldId];
|
|
375
|
+
const fieldDef = this.fieldMap[fieldId];
|
|
376
|
+
const options = fieldDef?.type === "select" || fieldDef?.type === "multiselect" || fieldDef?.type === "radio" || fieldDef?.type === "checkbox" ? fieldDef.options : void 0;
|
|
377
|
+
const hasScoreOptions = options?.some((o) => o.score !== void 0);
|
|
378
|
+
let val;
|
|
379
|
+
if (hasScoreOptions && options) {
|
|
380
|
+
const selected = fieldDef?.type === "multiselect" || fieldDef?.type === "checkbox" ? (Array.isArray(raw) ? raw : [raw]).filter(Boolean) : [raw];
|
|
381
|
+
val = selected.reduce((s, v) => {
|
|
382
|
+
const opt = options.find((o) => o.value === v || String(o.value) === String(v));
|
|
383
|
+
return s + (opt && "score" in opt && typeof opt.score === "number" ? opt.score : 0);
|
|
384
|
+
}, 0);
|
|
385
|
+
} else {
|
|
386
|
+
val = Number(raw) || 0;
|
|
387
|
+
}
|
|
375
388
|
return acc + val;
|
|
376
389
|
}, 0);
|
|
377
390
|
if (this.state.values[comp.target] !== sum) {
|