---
title: ui-bind
project: jComponent V19
version: 19.194
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v19/19-194/reference/ui-bind/
updated: 2026-11-18T13:58:24.464Z
---

# ui-bind

> The attributes and commands of the ui-bind element, and the binder object it creates.

The `<ui-bind>` element watches a path and updates the DOM when the value changes. Its `config` attribute holds a list of commands. [Data binding](../../guides/data-binding/) explains the concept.

## API

### path="path"

Type: `property`

Sets the path that the element watches.

The attribute accepts these forms:

| Value | Meaning |
| --- | --- |
| `form.name` | An absolute path. |
| `!form.name` | The commands are skipped while the value is `null` or `undefined`. |
| `?.name` | A path relative to the closest [`ui-plugin`](../ui-plugin/). |
| `*name` | A path inside `DEF.pathcommon`. |
| `%name` | A temporary path. |
| `@key` | A value stored with [`data()`](../component/#data) of the parent component. `@` alone is the value of that component and `@config.key` is a configuration key. |
| `.name` | A path inside the model of a [virtual binder](../vbinder/). `.` alone is the whole model. |
| `form.name --> expression` | Transforms the value with an expression that receives `value`. |

When the element has a path and no `config`, the path must contain a function, which is called with the element.

Example: Skipping empty values
```html
<ui-bind path="!form.name" config="text">Waiting</ui-bind>
```

Example: Transforming the value
```html
<ui-bind path="form.name --> value.toUpperCase()" config="text"></ui-bind>
<script>SET('form.name', 'peter');</script>
```

Example: Reading data of the parent component
```html
<ui-component name="card" config="title:Orders">
    <ui-bind path="@config.title" config="text"></ui-bind>
</ui-component>
<script>COMPONENT('card', function(self) {});</script>
```

Example: Calling a function with the element
```html
<ui-bind path="common.init" id="box"></ui-bind>
<script>
    window.common = { init: element => console.log(element.attr('id')) };  // box
</script>
```

### config="command:expression;command:expression"

Type: `property`

Holds the commands of the element.

Commands are separated by a semicolon. Each command has the form `name:expression`. See [Command syntax](#command-syntax).

Example: Two commands
```html
<ui-bind path="form.age" config="text:value + ' years';.adult:value >= 18"></ui-bind>
<script>SET('form.age', 20);</script>
```

### element="selector"

Type: `property`

Applies the commands to another element.

The value is a jQuery selector evaluated in the whole document.

Example: Updating an element elsewhere
```html
<ui-bind path="form.name" element="#target" config="text"></ui-bind>
<div id="target"></div>
<script>SET('form.name', 'Peter');</script>
```

### parent="selector"

Type: `property`

Applies the commands to the closest matching parent.

The value is a jQuery selector passed to `closest()`.

Example: Updating a parent element
```html
<div class="row">
    <ui-bind path="form.name" parent=".row" config="title:value"></ui-bind>
</div>
<script>SET('form.name', 'Peter');</script>
```

### child="selector"

Type: `property`

Applies the commands to the first matching descendant.

The attribute can be combined with [`parent`](#parent).

Example: Updating a child element
```html
<ui-bind path="form.name" child="b" config="text">
    <b></b>
</ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### plugin="path"

Type: `property`

Creates a scope directly on the element.

The value is the path of the scope.

Example: A scope on the element
```html
<ui-bind plugin="users" path="?.name" config="text"></ui-bind>

<script>
    PLUGIN('users', function(exports) {
        exports.set('name', 'Peter');
    });
</script>
```

### [!~]command [selector]:expression

Type: `type`

A command is a name followed by an optional expression.

The expression can have these forms:

| Form | Meaning |
| --- | --- |
| omitted | The value itself, as in `text`. |
| `value + 1` | A JavaScript expression that contains the word `value`. The variables `value`, `path` and `el` are available. |
| `value => value + 1` | An arrow function. |
| `common.format` | The path of a function called with `value`, `path` and `el`. |
| `?/format` | A method of the plugin of the closest scope. |

The prefixes and separators are:

| Syntax | Meaning |
| --- | --- |
| `command selector:expression` | Runs the command on the descendants that match the selector. |
| `text+title:value` | Runs one expression for several commands. |
| `!command` | Skips the command while the value is `null` or `undefined`. On the element itself, `text`, `html`, `title`, `value`, `src`, `checked`, `disabled` and `enabled` then return to their original content. |
| `~command` | Runs the command also while the element is hidden by `show`, `hide`, `visible` or `invisible`. |

Example: Expression forms
```html
<ui-bind path="form.name" config="text b:value.length;title:n => n + '!';.long:common.long">
    <b></b>
</ui-bind>
<script>
    window.common = { long: value => value.length > 3 };
    SET('form.name', 'Peter');
</script>
```

Example: One expression for two commands
```html
<ui-bind path="form.name" config="text+title:value"></ui-bind>
<script>SET('form.name', 'Peter');</script>
```

Example: Restoring the original content
```html
<ui-bind path="form.name" config="!text">Anonymous</ui-bind>
<script>
    SET('form.name', 'Peter');
    setTimeout(() => SET('form.name', null), 500);
</script>
```

Example: Updating a hidden element
```html
<ui-bind path="form.name" config="~text;hide:value">Anonymous</ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### text[:expression]

Type: `command`

Sets the text content.

The value is escaped. The [`format`](#format), [`currency`](#currency), [`helper`](#helper) and [`empty`](#empty) commands change the output.

Example: Using text
```html
<ui-bind path="form.name" config="text"></ui-bind>
<script>SET('form.name', '<b>Peter</b>');</script>
```

### html[:expression]

Type: `command`

Sets the HTML content.

The value is not escaped.

Example: Using html
```html
<ui-bind path="form.name" config="html:'<b>' + value + '</b>'"></ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### value[:expression]

Type: `command`

Sets the value of a form field.

The short name `val` works too.

Example: Using value
```html
<ui-bind path="form.name" config="value input">
    <input />
</ui-bind>
<script>
    SET('form.name', 'Peter');
    setTimeout(() => console.log($('input').val()), 500);  // Peter
</script>
```

### title[:expression]

Type: `command`

Sets the `title` attribute.

Example: Using title
```html
<ui-bind path="form.name" config="title"></ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### href[:expression]

Type: `command`

Sets the `href` attribute.

Example: Using href
```html
<ui-bind path="form.id" config="href a:'/users/' + value + '/'">
    <a>Detail</a>
</ui-bind>
<script>SET('form.id', 5);</script>
```

### src[:expression]

Type: `command`

Sets the `src` attribute.

Example: Using src
```html
<ui-bind path="form.photo" config="src img">
    <img />
</ui-bind>
<script>SET('form.photo', 'data:,');</script>
```

### attr name [selector]:expression

Type: `command`

Sets any attribute.

The name of the attribute follows the command. A selector can follow the name.

Example: Using attr
```html
<ui-bind path="form.id" config="attr data-id:value;attr data-ref b:value">
    <b></b>
</ui-bind>
<script>SET('form.id', 5);</script>
```

### .classname[ selector]:expression

Type: `command`

Toggles a CSS class by the result of the expression.

Write the name of the class after the dot.

Example: Toggling classes
```html
<ui-bind path="form.age" config=".adult:value >= 18;.minor:value < 18"></ui-bind>
<script>SET('form.age', 20);</script>
```

### class:classes

Type: `command`

Toggles CSS classes once, after the first update.

Separate several classes with a space.

Example: Using class
```html
<ui-bind path="form.name" config="class:ready"></ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### show[:expression]

Type: `command`

Shows the element when the expression is truthy.

Otherwise the element receives the `hidden` class. While hidden, the commands that follow are skipped unless they have the `~` prefix.

Example: Using show
```html
<ui-bind path="form.age" config="show:value >= 18">Adult</ui-bind>
<script>SET('form.age', 10);</script>
```

### hide[:expression]

Type: `command`

Hides the element when the expression is truthy.

The element receives the `hidden` class. The name `hidden` works too.

Example: Using hide
```html
<ui-bind path="form.age" config="hide:value >= 18">Minor</ui-bind>
<script>SET('form.age', 20);</script>
```

### visible[:expression]

Type: `command`

Keeps the layout space when the expression is falsy.

The element receives the `invisible` class when the expression is falsy.

Example: Using visible
```html
<ui-bind path="form.age" config="visible:value >= 18">Adult</ui-bind>
<script>SET('form.age', 10);</script>
```

### invisible[:expression]

Type: `command`

Adds the `invisible` class when the expression is truthy.

Example: Using invisible
```html
<ui-bind path="form.age" config="invisible:value >= 18">Minor</ui-bind>
<script>SET('form.age', 20);</script>
```

### checked[:expression]

Type: `command`

Sets the `checked` property of a field.

Example: Using checked
```html
<ui-bind path="form.active" config="checked input">
    <input type="checkbox" />
</ui-bind>
<script>
    SET('form.active', true);
    setTimeout(() => console.log($('input').prop('checked')), 500);  // true
</script>
```

### disabled[:expression]

Type: `command`

Disables fields and components when the expression is truthy.

The short name `disable` works too. Without a selector, the command applies to `ui-component`, `input`, `textarea`, `select` and `button` inside the element. Components receive the `disabled` configuration key.

Example: Using disabled
```html
<ui-bind path="form.locked" config="disabled">
    <button>Save</button>
</ui-bind>
<script>SET('form.locked', true);</script>
```

### enabled[:expression]

Type: `command`

Enables fields and components when the expression is truthy.

The short name `enable` works too. The default selector is the same as for [`disabled`](#disabled).

Example: Using enabled
```html
<ui-bind path="form.valid" config="enabled">
    <button>Save</button>
</ui-bind>
<script>SET('form.valid', false);</script>
```

### required selector:expression

Type: `command`

Sets the `required` configuration key of a component.

Add a selector, because the command has no default one.

Example: Using required
```html
<ui-bind path="form.strict" config="required ui-component:value">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    COMPONENT('box', function(self) {
        self.configure = (key, value) => key === 'required' && console.log(value);  // true
    });
    SET('form.strict', true);
</script>
```

### config:expression

Type: `command`

Reconfigures components with the result of the expression.

The default selector is `ui-component`.

Example: Using config
```html
<ui-bind path="form.title" config="config:'title:' + value">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    COMPONENT('box', function(self) {
        self.configure = (key, value) => key === 'title' && console.log(value);  // Orders
    });
    SET('form.title', 'Orders');
</script>
```

### set[:expression]

Type: `command`

Passes the result of the expression to the `setter` of a component without a path.

The default selector is `ui-component`. The component can write back to the same path.

Example: Using set
```html
<ui-bind path="form.name" config="set:value + '!'">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    COMPONENT('box', function(self) {
        self.setter = value => self.text(value);
    });
    SET('form.name', 'Peter');
</script>
```

### setter:'selector/method',value

Type: `command`

Calls a method of matching components.

The expression holds the arguments of `SETTER()`, evaluated with `value`, `path` and `el`.

Example: Using setter
```html
<ui-bind path="form.name" config="setter:'box/show',value">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    COMPONENT('box', function(self) {
        self.show = value => value && console.log(value);  // Peter
    });
    setTimeout(() => SET('form.name', 'Peter'), 500);
</script>
```

### template [selector][:selector-->attribute]

Type: `command`

Renders a Tangular template.

The template is the first `<script>` or `<template>` inside the element. The model has the properties `value` and `path`.

The optional `template:selector-->attribute` form updates only the changed child elements. The selector finds the items and the attribute identifies them. Read more in [Templates with Tangular](../../guides/tangular/).

Example: Using template
```html
<ui-bind path="form.items" config="template">
    <script type="text/html">
        {{ foreach m in value }}<li>{{ m }}</li>{{ end }}
    </script>
</ui-bind>
<script>SET('form.items', ['A', 'B']);</script>
```

### helpers:path

Type: `command`

Passes Tangular helpers to the template.

The value is a path to an object with helpers, or to a function that returns one.

Example: Using helpers
```html
<ui-bind path="form.name" config="template;helpers:common.helpers">
    <script type="text/html">{{ value | shout }}</script>
</ui-bind>
<script>
    window.common = { helpers: { shout: value => value + '!' } };
    SET('form.name', 'Peter');
</script>
```

### vbindarray

Type: `command`

Renders an array with a virtual binder per item.

The template is the first `<script>` or `<template>` inside the element. Paths inside the template start with a dot. See [Virtual binder](../vbinder/).

Example: Using vbindarray
```html
<ui-bind path="form.users" config="vbindarray">
    <script type="text/html">
        <div><ui-bind path=".name" config="text"></ui-bind></div>
    </script>
</ui-bind>
<script>SET('form.users', [{ name: 'Peter' }, { name: 'Anna' }]);</script>
```

### import:url

Type: `command`

Loads content into the element.

The value is one of these:

| Value | Meaning |
| --- | --- |
| A URL that starts with `/`, `http://` or `https://` | Imports the URL once. |
| `value` or `true` | Moves the first inner `<script>` or `<template>` into the DOM. |
| An expression | Imports the URL returned by the path value, once per URL. |

The import waits until the element is visible, so it can be combined with [`show`](#show).

Example: Inserting a template when the element is shown
```html
<ui-bind path="form.open" config="show;import:value">
    <script type="text/html"><b>Loaded</b></script>
</ui-bind>
<script>
    setTimeout(() => SET('form.open', true), 500);
</script>
```

### macro:name1,name2

Type: `command`

Attaches macros to the element.

Separate several names with a comma. See [Macro](../macro/).

Example: Using macro
```html
<ui-bind path="form.name" config="macro:shout"></ui-bind>
<script>
    MACRO('shout', function(self) {
        self.setter = value => self.text(value + '!');
    });
    SET('form.name', 'Peter');
</script>
```

### exec:path

Type: `command`

Calls a function on each update.

The function receives `value`, `path` and `el`, and `this` is the element. It always receives the raw value. The name `change` works too.

Example: Using exec
```html
<ui-bind path="form.name" config="exec:common.onchange"></ui-bind>
<script>
    window.common = { onchange: (value, path) => value && console.log(value, path) };  // Peter form.name
    setTimeout(() => SET('form.name', 'Peter'), 500);
</script>
```

### init:path

Type: `command`

Calls a function at the beginning of each update.

The function receives `value`, `path` and `el`.

Example: Using init
```html
<ui-bind path="form.name" config="init:common.oninit"></ui-bind>
<script>
    window.common = { oninit: value => value && console.log(value) };  // Peter
    SET('form.name', 'Peter');
</script>
```

### refresh:path

Type: `command`

Calls a function on each update while the element is visible.

The function receives `value`, `path` and `el`.

Example: Using refresh
```html
<ui-bind path="form.name" config="refresh:common.onrefresh"></ui-bind>
<script>
    window.common = { onrefresh: value => value && console.log(value) };  // Peter
    SET('form.name', 'Peter');
</script>
```

### click [selector]:path

Type: `command`

Calls a function when the element is clicked.

The function receives the jQuery element, the event, the current value and the path. A selector delegates the click to the matching descendants. Disabled inputs and buttons are ignored.

Example: Using click
```html
<ui-bind path="form.name" config="click button:common.onclick">
    <button>Save</button>
</ui-bind>
<script>
    window.common = {
        onclick: (element, event, value, path) => console.log(element.text(), value, path)  // Save Peter form.name
    };
    SET('form.name', 'Peter');
    setTimeout(() => $('button').click(), 500);
</script>
```

### format:format

Type: `command`

Formats a number or a date.

A number sets the decimal places. Any other text is a date format.

Example: Using format
```html
<ui-bind path="form.price" config="text;format:2"></ui-bind>
<script>SET('form.price', 1250);</script>
```

### currency:name

Type: `command`

Formats a number with a currency.

The name refers to a function in `DEF.currencies`.

Example: Using currency
```html
<ui-bind path="form.price" config="text;currency:eur"></ui-bind>
<script>
    DEF.currencies.eur = value => value.format(2) + ' EUR';
    SET('form.price', 1250);
</script>
```

### helper:name[(arguments)]

Type: `command`

Transforms the output with a Tangular helper.

The value is passed as the first argument of the helper. Other arguments can be written in parentheses.

Example: Using helper
```html
<ui-bind path="form.name" config="text;helper:wrap('*')"></ui-bind>
<script>
    Thelpers.wrap = (value, chars) => chars + value + chars;
    SET('form.name', 'Peter');
</script>
```

### empty[:text]

Type: `command`

Sets the text used for an empty value.

Without a value, the command uses `DEF.empty`, which is `---`.

Example: Using empty
```html
<ui-bind path="form.name" config="text;empty:Nothing"></ui-bind>
```

### default:expression

Type: `command`

Replaces `null` and `undefined` with a value.

The value is a JavaScript expression. The short name `def` works too.

Example: Using default
```html
<ui-bind path="form.name" config="text;default:'Anonymous'"></ui-bind>
```

### selector:selector

Type: `command`

Applies all commands to the matching descendants.

Example: Using selector
```html
<ui-bind path="form.name" config="selector:b;text">
    <b></b><b></b>
</ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### assign:path

Type: `command`

Writes the jQuery element to a path.

Example: Using assign
```html
<ui-bind id="box" path="form.name" config="assign:common.box;text"></ui-bind>
<script>
    setTimeout(() => console.log(GET('common.box').attr('id')), 500);  // box
</script>
```

### check:path

Type: `command`

Runs the commands only when a condition passes.

The value is a path to a truthy value, or `plugin/method`, which receives `value`, `path` and `el`.

Example: Using check
```html
<ui-bind path="form.name" config="check:form.ready;text">Waiting</ui-bind>
<script>SET('form.name', 'Peter');</script>
```

### delay:milliseconds

Type: `command`

Delays the update in milliseconds.

Repeated updates within the delay run once.

Example: Using delay
```html
<ui-bind path="form.name" config="delay:500;text"></ui-bind>
<script>
    SET('form.name', 'Peter');
    setTimeout(() => console.log($('ui-bind').text() || 'empty'), 200);  // empty
    setTimeout(() => console.log($('ui-bind').text()), 1100);  // Peter
</script>
```

### strict

Type: `command`

Ignores changes of nested paths.

The commands run only when the path itself or one of its parents changes.

Example: Using strict
```html
<ui-bind path="form.user" config="strict;exec:common.update"></ui-bind>
<script>
    window.common = { update: (value, path) => console.log(path) };
    SET('form.user', { name: 'Peter' });
    setTimeout(() => SET('form.user.name', 'Anna'), 500);
</script>
```

### track:field1,field2

Type: `command`

Runs the commands only for selected nested fields.

Separate several fields with a comma.

Example: Using track
```html
<ui-bind path="form.user" config="track:name;exec:common.update"></ui-bind>
<script>
    window.common = { update: (value, path) => console.log(path) };
    SET('form.user', { name: 'Peter', age: 20 });
    setTimeout(() => SET('form.user.age', 21), 500);
    setTimeout(() => SET('form.user.name', 'Anna'), 700);
</script>
```

### tracktype:type1,type2

Type: `command`

Runs the commands only for selected update types.

Separate several types with a comma.

Example: Using tracktype
```html
<ui-bind path="form.age" config="tracktype:2;exec:common.update"></ui-bind>
<script>
    window.common = { update: value => value && console.log(value) };
    setTimeout(() => SET('form.age', 10, 1), 500);
    setTimeout(() => SET('form.age', 20, 2), 700);
</script>
```

### changes

Type: `command`

Skips the commands when the value has not changed.

The value is compared with a hash.

Example: Using changes
```html
<ui-bind path="form.age" config="changes;exec:common.update"></ui-bind>
<script>
    window.common = { update: value => value && console.log(value) };
    setTimeout(() => SET('form.age', 10), 500);
    setTimeout(() => UPD('form.age'), 700);
</script>
```

### ready

Type: `command`

Waits for the components nested in the element.

The commands run when all nested components are ready.

Example: Using ready
```html
<ui-bind path="form.name" config="ready;exec:common.update">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    window.common = { update: () => console.log(FIND('box') ? 'found' : 'missing') };  // found
    COMPONENT('box', function(self) {});
</script>
```

### once

Type: `command`

Runs the commands only one time.

Example: Using once
```html
<ui-bind path="form.name" config="once;text"></ui-bind>
<script>
    SET('form.name', 'Peter');
    setTimeout(() => SET('form.name', 'Anna'), 700);
</script>
```

### focus:selector

Type: `command`

Moves the focus to a field after each update.

The value is a selector of descendants.

Example: Focusing a field
```html
<ui-bind path="form.name" config="focus:input">
    <input />
</ui-bind>
<script>
    SET('form.name', 'Peter');
</script>
```

### resize

Type: `command`

Calls the `resize` method of nested components after each update.

Example: Using resize
```html
<ui-bind path="form.name" config="resize">
    <ui-component name="box"></ui-component>
</ui-bind>
<script>
    COMPONENT('box', function(self) {
        self.resize = () => console.log('resized');  // resized
    });
    setTimeout(() => SET('form.name', 'Peter'), 500);
</script>
```

### binder.refresh()

Type: `method`

Runs the commands again with the current value of the path.

The binder is available as `element.ui` or through `$(element).binder()`.

Example: Refreshing a binder
```js
var binder = $('ui-bind').binder();
window.form.name = 'Anna';
binder.refresh();
console.log($('ui-bind').text());  // Anna
```

### binder.exec(value, path)

Type: `method`

Runs the commands with a custom value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The value passed to the commands. |
| `path` | `String` | yes |  | The path passed to the commands. |

The value is not written to the data model.

Example: Running the commands with a value
```js
var binder = $('ui-bind').binder();
binder.exec('Preview', 'form.name');
console.log($('ui-bind').text(), GET('form.name'));  // Preview Peter
```
