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
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
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
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
| Prop | Type | Unset | Meaning |
|---|---|---|---|
bind: | State | none | A name for a handle on the form, not a state: |
show: | one of its cases | onBlur | When a
|
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.
| Event | Sends | Meaning |
|---|---|---|
on submit | DOM | The form was submitted |
on reset | DOM | The 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.
Codes this can raise
These controls list the props' cases; the example below shows them written.