# lace:model

Bind a form input to a component property with two-way sync. The property is the source of truth: change it
on the server and the input re-renders; edit the input and the property updates.

## Syntax

```python
class Search(Component):
    query: str = ""
```
```django
<input lace:model="query">
<p>Searching for: {{ query }}</p>
```

By default binding is **deferred** - the value syncs on the *next* action, not on every keystroke, saving a
round-trip per character. Modifiers change when a sync happens:

```django
<input lace:model.live="q">                 {# every keystroke #}
<input lace:model.live.debounce.300ms="q">  {# debounced (default 300ms) #}
<input lace:model.blur="email">             {# on focus loss - good for validation #}
<input lace:model.change="choice">          {# on change - selects, checkboxes, radios #}
```

```interlace-demo
ModelModifiers
```

## Modifiers

| Modifier | Syncs | Use for |
|---|---|---|
| (none) | on the next action | forms - one round-trip on submit |
| `.live` | every keystroke | live search / preview (add `.debounce.Nms` to throttle) |
| `.blur` | when the field loses focus | per-field validation |
| `.change` | on the change event | selects, checkboxes, radios |

## Nested properties

Dotted paths bind into nested data - dict keys, or fields of a bound model:

```django
<input lace:model="settings.notifications">
<input lace:model="user.email">
```

> Binding to a **Django model field** (like `user.email`) requires that field on the component's binding
> allowlist - see [Working with Models](/docs/working-with-models/). Plain properties and dict keys need no
> allowlist.

## Reacting to changes

Define an `updated_<property>` method to run code whenever a property changes:

```python
class MyComponent(Component):
    search_query: str = ""

    def updated_search_query(self, value):
        self.results = search_database(value)
```
