--- url: /reference/items/DataModel/examples.md --- # Examples ## Checkbox :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Checkboxes When working with multiple checkboxes, it can be useful to store the value in an array rather than a simple boolean indicating if the checkbox is checked. Checkboxes sharing the same value will be synced and checked or unchecked together. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Radio Radio inputs sharing the same native `name` inside a [`DataScope`](../DataScope/index.md) behave as a single keyed value: the checked radio is the current source, and selecting another one updates every subscriber for that key. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Select :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Select multiple :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Number Number inputs resolve their value with the `valueAsNumber` property, so computed callbacks and mutation helpers such as [`increment()`](../DataBind/js-api.md#increment) work with a real number. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Date Date inputs resolve their value with the `valueAsDate` property. The bound value is a `Date` object (or `null` when empty), so it can be formatted freely in [virtual bindings](../DataBind/index.md#multiple-virtual-bindings) or computed callbacks. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` ::: ## Textarea Textareas behave like text inputs and bind their `value` property. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(Action); registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataComputed); registerComponent(DataModel); ``` :::