F04
Warning
Forms and bindings
F04 — A checkbox that shows a state and never changes it
Checkbox(checked: x) with no bind: and no on change draws x, and a click toggles the box while x stays as it was.
What the compiler said
warning[F04]: this `Checkbox` shows `checked:` but nothing changes it, so a click toggles the box and not the state --> src/App.wf:4:5 | 4 | Checkbox(checked: agree, label: "I agree") | ^^^^^^^^ = help: Write `bind:` to keep the box and the state together, or handle `on change` = docs: https://webfluent.monzeromer.dev/errors/F04
Your editor offers this fix: Change to bind:. wf fix --code F04 applies it to every place it fits.
The fix
Broken
page P(path: "/", title: "T", description: "D") {
state agree = false
Heading("Terms").h1
Checkbox(checked: agree, label: "I agree")
}
Fixed
page P(path: "/", title: "T", description: "D") {
state agree = false
Heading("Terms").h1
Checkbox(bind: agree, label: "I agree")
}
Checkbox(bind: agree, label: "I agree").
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Warning.
lints may lower it:
"lints": { "F04": "off" }
// wf-allow(F04)