Form
src/lib/components/ui/form/
Purpose
Form primitives built on top of formsnap (the shadcn-svelte™ form layer).
The barrel re-exports the standard primitives — Field, Control, Label,
Description, FieldErrors, Fieldset, Legend, ElementField,
Button — and adds one Primebrick extension:
TranslatedFieldErrors(translated-field-errors.svelte) — drop-in replacement forFieldErrorsthat translates each error string through$t. Errors may be either a plain translation key (validation.required) or a key with JSON params (validation.tooShort|{"min": 3}). Malformed JSON falls back to translating the key alone.
Origin
shadcn-svelte™ (extended) — base primitives come from formsnap /
shadcn-svelte™. TranslatedFieldErrors is a Primebrick addition that wires
the error list into the project's i18n ($lib/i18n).
Usage
Standard field with translated errors
Code
The backend (or formsnap) emits errors as translation keys. The component
renders them through $t, so the user sees a localized message.
Error key with params
If the validator emits validation.tooShort|{"min": 3}, the component calls
$t("validation.tooShort", { min: 3 }) and renders the localized result.
Custom error rendering
Code
When a children snippet is provided, it overrides the default translation
rendering — useful for debugging raw error keys.
Fieldset + Legend
Code
Props
Full prop table: see API reference — form.
Key exports (all re-exported from the barrel with Form* aliases):
Field/FormField—formsnapfield context.Control/FormControl—formsnap.Control.Label/FormLabel— styled label.Description/FormDescription— helper text under the control.FieldErrors/FormFieldErrors— raw (untranslated) error list.TranslatedFieldErrors/TranslatedFormFieldErrors— translated error list. AcceptsFieldErrorsPropspluserrorClasses(string) for per-error styling and an optionalchildrensnippet override.Fieldset/FormFieldset,Legend/FormLegend— grouping primitives.ElementField/FormElementField— field for a single form element.Button/FormButton— form submit button.