Reference

Form

Groups controls; on submit runs when it is submitted, and the page never navigates away.

Form(bind: State, show: Enum) { … }

Before 5.0

show

onBlur

onSubmit

live

Not signed in yet.

Example

wf

state email = "" state password = "" state sent = "" validate email { required "Enter your email" email "That is not an email address" } validate password { required minLength(8) "Use at least 8 characters" } Form(bind: form, show: .onBlur) { on submit { sent = "Signed in as {email}" } Input(bind: email, label: "Email").email Input(bind: password, label: "Password").password Button("Sign in", type: .submit, disabled: !form.valid).primary } Text(if sent == "" { "Not signed in yet." } else { sent }).muted

Messages only after a submit

wf

state name = "" validate name { required "Tell us your name" } Form(bind: form, show: .onSubmit) { on submit { log(name) } Input(bind: name, label: "Name") Button("Save", type: .submit).primary }

Starting again

wf

state title = "Untitled" Form(bind: draft) { on submit { log(title) } Input(bind: title, label: "Title") Row(gap: .sm) { Button("Publish", type: .submit).primary Button("Reset") { on click { draft.reset() } } } }

Props

Props of Form
PropTypeUnsetMeaning

bind:

State

none

A name for a handle on the form, not a state: form.valid, form.errors, form.touched, form.pending, form.values by field name, form.reset(), form.submit(), form.apply(serverErrors)

show:

one of its cases

onBlur

When a validate block's message is shown on its field. Written as a flag, .onBlur, or by name, show: .onBlur.

  • .onBlur (the default): Once the reader has left the field (the default)
  • .onSubmit: Only after a submit
  • .live: As they type

Attribute families: global, aria, data, form. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.onBlur

.onSubmit

.live

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events Form answers
EventSendsMeaning
on submitDOMThe form was submitted
on resetDOMThe form was reset

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Renders with the class wf-form, stable across releases, so a stylesheet may target it.

These controls list the props' cases; the example below shows them written.