Bind a control’s live value

Use bind:value when an input and a signal represent the same value. This example starts with an empty string and shows that string in a paragraph.

input.wisp
<script>let draft: Signal<String> = Signal::new(String::new());</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }input { width: 240px; }</style><input bind:value={draft} /><p>You typed: {draft}</p>
vapors component source

The binding writes the signal’s value into the control. When the control emits its input event, the binding writes the new value back to the signal. The paragraph’s expression reads the same state.

A binding owns the update

Do not attach an input handler that also tries to provide the same binding update. The compiler refuses a binding combined with a handler for the same event, so one place owns that control’s state update.

Other events can still have their documented handlers. The restriction is on a binding and handler for the same event, not a general ban on event listeners.

Value and checked are different

Use bind:value for a text, number or range input. Use bind:checked for a checkbox’s boolean state. A literal value attribute describes an initial attribute; it is not a two-way binding.

The next lesson uses a checkbox to choose a conditional branch.

Does the paragraph need its own input event listener?

No. It reads draft through the reactive expression. The input binding updates draft; the paragraph's effect follows that change.

Run and edit

Save the example over crates/demos/demos/hello.wisp and run cargo run -p vapors-app --example demo -- hello. Type into the field and watch the paragraph update. Change the initial string, rebuild and check that both the field and paragraph start with that value.

The field demo shows the same binding in a styled layout. See Elements and events for the supported control types.