qat

Form and field

Form, Field. They are copied into your app’s ui/ by qatjs add form: the code is yours to edit.

Example

For the receipt only.
Example.qx33 lines, 1 reactive nameOpen in the playground
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 state

Add it

shell1 line
npx qatjs add form

Form

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>.

Form: props
PropTypeAttribute
ofBoundFormproperty only
submit(values: any) => unknownproperty only
labelstringyes
classstringyes

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>.

Field: props
PropTypeAttribute
namestringyes
labelQatNodeproperty only
helpQatNodeproperty only
ofBoundFormproperty only
placeholderstringyes
autocompletestringyes
size'sm' | 'md' | 'lg'yes

Keys

KeyDoes
Enterin a field, submit: every error shown, the first invalid field focused