Lays out a label, a control, its description and its errors.
We will never share your address.
Installation
uvx django_shadcn@latest add field
Usage
<c-field>
<c-field.label for="email">Email</c-field.label>
<c-input id="email" type="email" />
<c-field.description>We will never share your address.</c-field.description>
</c-field>
Form
covers the same ground with a smaller surface. Field is the newer shadcn/ui
component: more parts, orientations, and a group that lays out several
fields at once.
<c-field orientation="horizontal">
<c-checkbox id="terms" />
<c-field.content>
<c-field.label for="terms">Accept the terms</c-field.label>
<c-field.description>You agree to our terms.</c-field.description>
</c-field.content>
</c-field>
Fieldset and legend
<c-field.set>
<c-field.legend>Notifications</c-field.legend>
<c-field.description>Choose how you want to be reached.</c-field.description>
<c-field.group>...</c-field.group>
</c-field.set>
Separator
or
<c-field.separator>or</c-field.separator>
Errors
Password is too short.
Handle is already taken.
Handle must be lowercase.
<c-field.error>Password is too short.</c-field.error>
<!-- or straight from a Django form field -->
<c-field.error :errors="form.handle.errors" />
Upstream, FieldError takes either children or an array of errors and
renders a list when there is more than one. Here errors takes a Django
form field's error list directly, with the same rule: one error inline,
several as a bulleted list. Nothing renders when both are empty.