Show a form

Show a form

Load a form file and draw it with FormView.

Load it

formQuery loads a form and everything it fetches before it opens, once per visit.

import { formQuery } from "#form-engine";

const { data: form } = useQuery(formQuery({
  id: "cafe-licence",
  load: () => import("~/forms/cafe-licence"),
}));

Draw it

<FormView
  v-if="form"
  :form="form"
  title="Café licence"
  ministry="City hall"
  back-to="/"
  leave-to="/drafts"
  :save="save"
  :submit="submit"
/>

back-to and leave-to are optional. Leave out back-to and the first step has no Back; leave out leave-to and there is no Save & leave, which suits a form inside another page.

save stores a draft and throws if it cannot. submit returns { next }, where to go once it is sent, or { errors }, which the form places on the fields they name.

Both get (payload, values, sends): the payload for your API, the answers as they are on screen, and any sections sent apart.

Leaving

The form asks before the person leaves with answers it has not saved. :leave-guard="false" turns that off, for a form shown inside another page.