UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

38 lines (37 loc) • 901 B
import { normalisePath as e } from "../utils/paths.js"; import { toFormApi as t } from "./formRuntime.js"; //#region src/runtime/serverErrors.ts var n = class extends Error { errors; constructor(e, t) { super(t ?? e.form ?? "The server rejected the submission"), this.name = "FormSubmitError", this.errors = e; } }; function r(n, r) { let i = t(n), a = []; r.form && a.push(r.form); let o = r.fields ?? {}; for (let [t, n] of Object.entries(o)) { if (!n) continue; let r = e(t); if (!i.getFieldMeta(r)) { a.push(n); continue; } i.setFieldMeta(r, (e) => ({ ...e, errorMap: { ...e.errorMap, onServer: n }, errorSourceMap: { ...e.errorSourceMap, onServer: "field" } })); } i.setErrorMap({ onServer: a.length === 0 ? void 0 : a }); } //#endregion export { n as FormSubmitError, r as applyServerErrors }; //# sourceMappingURL=serverErrors.js.map