Form and field
Form, Field. They are copied into your app’s ui/ by qatjs add form: the code is yours to edit.
Example
import { form } from '@qatjs/form'
import Button from './ui/button/button.qx'
import { Field, Form } from './ui/form/form.qx'
export default function Example() {
let f = form({
email: {
type: 'email',
required: true,
message: { valueMissing: 'Enter your email', typeMismatch: 'That is not an email address' },
},
note: { maxLength: 200 },
receipt: { type: 'checkbox', value: true },
})
let sent = state('')
return (
<Form of={f} submit={(v) => (sent = v.email)} label="Delivery">
<Field name="email" label="Email" help="For the receipt only." autocomplete="email" />
<Field name="note" label="Note to the courier">
<textarea rows={3}></textarea>
</Field>
<Field name="receipt" label="Send a receipt" />
<Button type="submit" variant="primary">
Save
</Button>
</Form>
{if (sent)}
<p role="status">
Saved for {sent}
</p>
{/if}
)
}sent stateAdd it
npx qatjs add formForm
The <form>: `of` is the form() its fields bind to, `submit` runs with the values once every field is valid. As a custom element: <ui-form>.
| Prop | Type | Attribute |
|---|---|---|
of | BoundForm | property only |
submit | (values: any) => unknown | property only |
label | string | yes |
class | string | yes |
Field
A field of the form around it (or of `of`): label, control, help or error, the required marker. As a custom element: <ui-field>.
| Prop | Type | Attribute |
|---|---|---|
name | string | yes |
label | QatNode | property only |
help | QatNode | property only |
of | BoundForm | property only |
placeholder | string | yes |
autocomplete | string | yes |
size | 'sm' | 'md' | 'lg' | yes |
Keys
| Key | Does |
|---|---|
| Enter | in a field, submit: every error shown, the first invalid field focused |