The data-bind attribute is used to declaratively bind DOM element attributes to values in the state.
<input data-bind="value:form.name"> <!-- binds input's value to form.name -->Use semicolons to bind multiple attributes:
<input data-bind="value:form.name; placeholder:form.placeholder">Multiline formatting is also supported and recommended for clarity:
<input
data-bind="
value:form.name;
placeholder:form.placeholder;
disabled:form.locked;
"
/>
⚠️ Trailing semicolons are optional.
You can bind to most standard DOM attributes, including:
valuecheckedselecteddisabledstyleclasssrc,hrefaria-*,data-*
By default, binding to value or checked will establish a two-way connection using oninput or onchange events.
<input type="range" data-bind="value:settings.volume">🧠 The framework automatically listens for
inputorchangeand updatessettings.volumeaccordingly.
You can apply input filters on binding using the | filter syntax:
<input data-bind="value|number:settings.count">In this example:
- The input's
valueis parsed as a number before updatingsettings.count
You can also filter values when displaying them in bound attributes:
<input data-bind="value|fix,2:price">This displays the value rounded to 2 decimal places.
You can bind event listeners via data-bind:
<input data-bind="oninput:handleInput">This is preferred over oninput="..." to avoid unsafe HTML evaluation.
In your state class:
handleInput(event) {
this.message = event.target.value;
}- Avoid introducing custom attribute syntax
- Keep
data-binddeclarative, consistent with HTML style - Support one-way and two-way bindings
- Enable clean separation of state, logic, and template structure
See also: Wildcard Paths, State Class