UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

77 lines (76 loc) 1.98 kB
import { jsx as f } from "react/jsx-runtime"; import { useFormikContext as h } from "formik"; function d() { const { errors: t } = h(), o = i(t); function r(...e) { return e.length ? e.some((s) => o.includes(s)) : o.length > 0; } return { hasAnyError: r }; } function i(t) { const o = []; let r; for (r in t) { const e = t[r]; if (e) switch (typeof e) { case "string": { o.push(r); break; } case "object": { let s = []; if (Array.isArray(e) ? e.forEach((n, c) => { if (n) switch (typeof n) { // a single error, for the entire object in the array. Could be because of // validation after each field was individually validated. case "string": { s.push(c.toString()); break; } case "object": { const a = i(n).map((u) => `${c}.${u}`); a.length && s.push(c.toString(), ...a); break; } default: throw new Error("Unexpected item type"); } }) : s = i(e), s.length) { const n = s.map((c) => `${r}.${c}`); o.push(r, ...n); } break; } default: throw new Error("Unexpected error type"); } } return o; } const m = (t) => { const { getFieldMeta: o } = h(), { error: r } = t ? o(t) : { error: "" }, e = t && r && typeof r == "string" ? [r] : []; return { hasErrors: e.length > 0, errors: e }; }, g = ({ errors: t }) => /* @__PURE__ */ f("div", { className: "formio-errors invalid-feedback", children: t.map((o, r) => /* @__PURE__ */ f("div", { className: "form-text error", children: o }, r)) }); export { g as ErrorList, i as getErrorNames, d as useErrorChecker, m as useValidationErrors };