Form
Fields stacked in a card, with the actions in its footer.
Updated
Default
<form class="mx-auto max-w-xl">
{ui card, title: 'New project', description: 'Where it lives and who can see it.'}
<div class="flex flex-col gap-4">
{ui field, name: 'name', label: 'Name'}
{ui input, name: 'name', placeholder: 'Annual report', required: true /}
{/ui}
{ui field, name: 'summary', label: 'Summary', hint: 'Shown on the project list.'}
{ui textarea, name: 'summary' /}
{/ui}
{ui field, name: 'visibility', label: 'Visibility'}
{ui select,
name: 'visibility',
options: ['private' => 'Private', 'team' => 'Team', 'public' => 'Public'],
value: 'team',
/}
{/ui}
{ui field}
{ui switch, name: 'notify', label: 'Email me about activity', checked: true /}
{/ui}
</div>
{block footer}
{ui button, title: 'Cancel', class: 'button-ghost' /}
{ui button, title: 'Create project' /}
{/block}
{/ui}
</form>
The form wraps the card, so the footer's buttons submit it. Fields stack in a flex flex-col gap-4 body, each with its own label and hint. A switch fits a yes or no setting better than a lone checkbox, and the primary action comes last.
With errors
<form class="mx-auto max-w-xl">
{ui card, title: 'New project'}
<div class="flex flex-col gap-4">
{ui alert,
title: 'Fix 2 things',
description: 'The project was not created.',
icon: 'circle-alert',
class: 'alert-destructive',
/}
{ui field, name: 'name', label: 'Name', error: 'A name is required.'}
{ui input, name: 'name', invalid: true /}
{/ui}
{ui field,
name: 'slug',
label: 'Slug',
error: 'Use lowercase letters, numbers and dashes.',
}
{ui input, name: 'slug', value: 'Not A Slug', invalid: true /}
{/ui}
</div>
{block footer}
{ui button, title: 'Create project' /}
{/block}
{/ui}
</form>
A field's error replaces its hint and marks the control invalid, so the message sits next to the input that caused it. An alert at the top of the body counts the problems for anyone who submitted without scrolling to see them. The server renders this version after a failed submit, and the user's values come back in each value.