{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "jsonforms-utils",
  "description": "Utility functions for JSONForms — includes translateError for rendering custom error messages from JSON Schema errorMessage annotations.",
  "files": [
    {
      "path": "registry/forms/utils.ts",
      "content": "/**\n * Translates a JSONForms AJV error to a human-readable message.\n * Reads `errorMessage` from the field's JSON Schema — supports both\n * per-keyword objects and a single string fallback.\n *\n * Usage: pass to `<JsonForms i18n={{ translateError }} />`\n */\nexport const translateError = (error: {\n    keyword: string;\n    parentSchema?: Record<string, unknown>;\n}): string => {\n    const customMessages = error.parentSchema?.errorMessage;\n    if (customMessages && typeof customMessages === 'object') {\n        return (customMessages as Record<string, string>)[error.keyword] ?? '';\n    }\n    if (typeof customMessages === 'string') return customMessages;\n    return '';\n};\n\n/**\n * Controls when a field first shows its error message.\n *\n * - `'onBlur'`   — show after the field loses focus for the first time\n * - `'onSubmit'` — show all errors when the form is submitted\n *\n * Re-validation (updating a visible error as the user types) is handled\n * automatically by JSONForms — no extra config needed.\n *\n * Mirrors Conform's `shouldValidate` API.\n */\nexport type ShouldValidate = 'onBlur' | 'onSubmit';\n\n/**\n * Determines whether a field's error should be visible.\n *\n * @param config  - JSONForms config object; reads `shouldValidate`\n * @param touched - whether the field has been blurred at least once (used by `onBlur`)\n */\nexport const shouldShowError = (\n    config: { shouldValidate?: ShouldValidate } | undefined,\n    touched: boolean\n): boolean => {\n    if (config?.shouldValidate === 'onBlur') return touched;\n    if (config?.shouldValidate === 'onSubmit') return true;\n    return false;\n};\n",
      "type": "registry:lib",
      "target": "components/forms/utils.ts"
    }
  ],
  "type": "registry:lib"
}