UNPKG

@mantine/form

Version:

Mantine form management library

24 lines (23 loc) 961 B
"use client"; import { filterErrors } from "./hooks/use-form-errors/filter-errors/filter-errors.mjs"; //#region packages/@mantine/form/src/schema-resolver.ts function issuesToFormErrors(issues) { const errors = {}; for (const issue of issues) { const path = issue.path ? issue.path.map((segment) => typeof segment === "object" ? segment.key : segment).join(".") : ""; if (!errors[path]) errors[path] = issue.message; } return filterErrors(errors); } function schemaResolver(schema, _options) { const sync = _options?.sync ?? false; return ((values) => { const result = schema["~standard"].validate(values); if (result instanceof Promise) return result.then((resolved) => resolved.issues ? issuesToFormErrors(resolved.issues) : {}); const errors = result.issues ? issuesToFormErrors(result.issues) : {}; return sync ? errors : Promise.resolve(errors); }); } //#endregion export { schemaResolver }; //# sourceMappingURL=schema-resolver.mjs.map