---
title: ui-bind
project: jComponent V20
version: 20.015
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/reference/ui-bind/
updated: 2026-11-22T18:42:02.302Z
---

# ui-bind

> The attributes and the commands of the ui-bind element.

The `<ui-bind>` element updates the page each time the value at a path changes. The `config` attribute holds a list of commands separated with `;`. The [Data binding](../../guides/data-binding/) guide explains how to use it.

A command has the form `name:expression`, or `name selector:expression` to act on the elements found by a selector inside the target. Without an expression, the command uses the value at the path. The expression is JavaScript and can use `value`, `path`, `flags`, `element` and `el` (the same as `element`). Join command names with `+` to give them the same expression, for example `text+title:value`. Write `\\;` for a semicolon inside an expression. All commands run once when the element is created, with the current value at the path. An error in an expression is written to the console and the commands continue.

## API

### path="path"

Type: `property`

The path to observe.

A `?` is replaced with the path of the parent plugin. With a `!` at the beginning (`!common.user`), the commands do not run while the value is `null` or `undefined`.

Example: Skip empty values
```html
<ui-bind path="!common.user" config="text:value.name"></ui-bind>

<script>
SET('common.user', { name: 'Peter' });
console.log($('ui-bind').text());
// logs: Peter
</script>
```

### config="commands"

Type: `property`

The commands, separated with `;`.

The values are kept as strings, because they are compiled as JavaScript.

### element="selector"

Type: `property`

Runs the commands on the elements found by a selector in the whole document.

Example: Update an element elsewhere in the page
```html
<h1 id="title"></h1>
<ui-bind path="common.title" element="#title" config="text"></ui-bind>

<script>
SET('common.title', 'Orders');
console.log($('#title').text());
// logs: Orders
</script>
```

### child="selector"

Type: `property`

Runs the commands on the elements found by a selector inside the element.

The `value` command needs this attribute or a selector to reach an input.

Example: Fill an input
```html
<ui-bind path="common.email" child="input" config="value"><input /></ui-bind>

<script>
SET('common.email', 'info@example.com');
console.log($('input').val());
// logs: info@example.com
</script>
```

### parent="selector"

Type: `property`

Runs the commands on the closest parent found by a selector.

Example: Change a parent element
```html
<div class="row">
    <ui-bind path="common.active" parent=".row" config=".selected"></ui-bind>
</div>

<script>
SET('common.active', true);
console.log($('.row').attr('class'));
// logs: row selected
</script>
```

### plugin="path"

Type: `property`

Creates a plugin on the element itself, and a `?` in the path refers to it.

Example: A binder with its own plugin
```html
<ui-bind plugin="clock" path="?.time" config="text"></ui-bind>

<script>
PLUGIN('clock', function(exports) {
    exports.make = () => exports.set('time', '12:00');
});

console.log($('ui-bind').text());
// logs: 12:00
</script>
```

### .name:expression

Type: `command`

Toggles the CSS class `name` according to the result of the expression.

Example: Toggle classes
```html
<ui-bind path="common.count" config=".empty:!value;.many:value > 10"></ui-bind>

<script>
SET('common.count', 20);
console.log($('ui-bind').attr('class'));
// logs: many
</script>
```

### text:expression

Type: `command`

Sets the text of the element. HTML is escaped.

A `null`, `undefined`, `false` or empty-string result writes the value of the `empty` command, and `0` is written as `0`. Nothing is written while the element is hidden by `show`, `hide`, `visible` or `invisible`, unless `forcerender` allows it.

Example: Show a text
```html
<ui-bind path="common.name" config="text:value.toUpperCase()"></ui-bind>

<script>
SET('common.name', 'anna');
console.log($('ui-bind').text());
// logs: ANNA
</script>
```

### html:expression

Type: `command`

Sets the HTML content of the element.

It follows the same rules as `text`, without escaping.

Example: Render markup
```html
<ui-bind path="common.name" config="html:'<b>' + value + '</b>'"></ui-bind>

<script>
SET('common.name', 'Anna');
console.log($('ui-bind').html());
// logs: <b>Anna</b>
</script>
```

### value selector:expression

Type: `command`

Sets the value of a form control.

Use a selector or the `child` attribute, because the `<ui-bind>` element is not a control itself.

Example: Fill an input with a selector
```html
<ui-bind path="common.city" config="value input"><input /></ui-bind>

<script>
SET('common.city', 'Bratislava');
console.log($('input').val());
// logs: Bratislava
</script>
```

### title:expression

Type: `command`

Sets the `title` attribute.

Example: Text and title together
```html
<ui-bind path="common.name" config="text+title:value"></ui-bind>

<script>
ON('ready', function() {
    SET('common.name', 'Anna');
    console.log($('ui-bind').text(), $('ui-bind').attr('title'));
});
// logs: Anna Anna
</script>
```

### href:expression

Type: `command`

Sets the `href` attribute.

### src:expression

Type: `command`

Sets the `src` attribute.

Example: Set attributes with selectors
```html
<ui-bind path="common.user" config="href a:'/users/' + value.id;title a:value.name;src img:value.photo">
    <a><img /></a>
</ui-bind>

<script>
SET('common.user', { id: 7, name: 'Anna', photo: '/a.png' });
console.log($('ui-bind').html().trim());
// logs: <a href="/users/7" title="Anna"><img src="/a.png"></a>
</script>
```

### attr name [selector]:expression

Type: `command`

Sets the attribute `name`.

Example: Set a custom attribute
```html
<ui-bind path="common.id" config="attr data-id:value"></ui-bind>

<script>
SET('common.id', 5);
console.log($('ui-bind').attr('data-id'));
// logs: 5
</script>
```

### show:expression

Type: `command`

Removes the CSS class `hidden` when the result is truthy and adds it otherwise.

Example: Show and hide
```html
<ui-bind path="common.items" config="show:value > 0">Items</ui-bind>
<ui-bind path="common.items" config="hide:value > 0">Empty</ui-bind>

<script>
SET('common.items', 3);
console.log($('ui-bind').eq(0).hclass('hidden'), $('ui-bind').eq(1).hclass('hidden'));
// logs: false true
</script>
```

### hide:expression

Type: `command`

Adds the CSS class `hidden` when the result is truthy and removes it otherwise.

### visible:expression

Type: `command`

Removes the CSS class `invisible` when the result is truthy and adds it otherwise.

### invisible:expression

Type: `command`

Adds the CSS class `invisible` when the result is truthy and removes it otherwise.

Example: Keep the space of the element
```html
<ui-bind path="common.ready" config="invisible:!value">Loaded</ui-bind>

<script>
console.log($('ui-bind').attr('class'));
// logs: invisible
SET('common.ready', true);
console.log($('ui-bind').hclass('invisible'));
// logs: false
</script>
```

### forcerender:expression

Type: `command`

Allows `text`, `html` and `template` to render while the element is hidden, when the result is truthy.

Example: Render into a hidden element
```html
<ui-bind id="a" path="common.name" config="show:false;text"></ui-bind>
<ui-bind id="b" path="common.name" config="show:false;forcerender:true;text"></ui-bind>

<script>
SET('common.name', 'Anna');
console.log($('#a').text() === '', $('#b').text());
// logs: true Anna
</script>
```

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

Type: `command`

Renders a Tangular template with the value.

The template comes from a `<script>` or `<template>` element inside the target, from the HTML of the target, or from the element in `{selector}`. The model contains `value`, `path` and `element`. The text `SCR` in a template is replaced with `script`.

With `selector --> attribute`, only the elements matching the selector are updated. Existing elements with the same attribute value stay in the page. Without an attribute, whole elements are compared. See [Templates with Tangular](../../guides/tangular/).

Example: Render a list
```html
<ui-bind path="common.users" config="template">
    <script type="text/html">
        {{ foreach m in value }}<b>{{ m }}</b>{{ end }}
    </script>
</ui-bind>

<script>
SET('common.users', ['Anna', 'Peter']);
console.log($('ui-bind').html().trim());
// logs: <b>Anna</b><b>Peter</b>
</script>
```

Example: Use an external template and update only changed rows
```html
<script type="text/html" id="row"><div data-id="{{ value }}">{{ value }}</div></script>
<ui-bind path="common.id" config="template:{#row} div --> data-id"></ui-bind>

<script>
SET('common.id', 1);
var first = $('ui-bind div')[0];
SET('common.id', 1);
console.log(first === $('ui-bind div')[0]);
// logs: true
</script>
```

### helpers:path

Type: `command`

Sets the object with the Tangular helpers for the `template` command.

Example: Custom helpers
```html
<ui-bind path="common.name" config="template;helpers:FUNC.helpers">
    <template>{{ value | shout }}</template>
</ui-bind>

<script>
FUNC.helpers = {
    shout: value => (value || '').toUpperCase() + '!'
};

SET('common.name', 'anna');
console.log($('ui-bind').html().trim());
// logs: ANNA!
</script>
```

### format:value

Type: `command`

Formats a `Date` value for the `text`, `html`, `value`, `title`, `href`, `src` and `attr` commands.

Example: Format a date
```html
<ui-bind path="common.date" config="text;format:dd.MM.yyyy"></ui-bind>

<script>
SET('common.date', new Date(2024, 0, 15));
console.log($('ui-bind').text());
// logs: 15.01.2024
</script>
```

### empty:text

Type: `command`

Sets the text written by `text`, `html`, `value`, `title`, `href` and `src` when the result is `null`, `undefined`, `false` or an empty string.

Without a value, the text in `DEF.empty` is used (`---`).

Example: Show a placeholder
```html
<ui-bind path="common.note" config="text;empty:No note"></ui-bind>

<script>
console.log($('ui-bind').text());
// logs: No note
</script>
```

### class:name

Type: `command`

Toggles a CSS class on the `<ui-bind>` element once, after the commands run for the first time.

Example: Mark the element as rendered
```html
<ui-bind path="common.name" config="text;class:rendered"></ui-bind>

<script>
console.log($('ui-bind').attr('class'));
// logs: rendered
</script>
```

### exec:path

Type: `command`

Calls a function with the value, the path and the target element.

A `?` in the value is replaced with the path of the parent plugin. The form `?/method` calls a method of the plugin.

Example: Call a function on each change
```html
<ui-bind path="common.total" config="exec:FUNC.total"></ui-bind>

<script>
FUNC.total = function(value, path, element) {
    value && console.log(value, path.toString(), element[0].tagName);
};

SET('common.total', 10);
// logs: 10 common.total UI-BIND
</script>
```

### refresh:path

Type: `command`

Calls a function with the value, the path and the target element, in the same way as `exec`.

### focus:selector

Type: `command`

Moves the focus to the first visible element found by the selector, 500 milliseconds after the change.

The focus is not moved on mobile devices.

Example: Focus an input
```html
<ui-bind path="common.open" config="focus:input"><input id="name" /></ui-bind>

<script>
setTimeout(() => console.log(document.activeElement.id), 700);
// logs: name
</script>
```

### checked:expression

Type: `command`

Sets the `checked` state of the checkboxes and radio buttons inside the target.

Example: Check a checkbox
```html
<ui-bind path="common.agree" config="checked"><input type="checkbox" /></ui-bind>

<script>
SET('common.agree', true);
console.log($('input')[0].checked);
// logs: true
</script>
```

### disabled:expression

Type: `command`

Disables the form controls and the components inside the target when the result is truthy.

Form controls are `input`, `select`, `textarea` and `button`. Components receive the `disabled` config key.

Example: Disable a form
```html
<ui-bind path="common.locked" config="disabled">
    <input />
    <ui-component name="field"></ui-component>
</ui-bind>

<script>
COMPONENT('field', function(self) {});

SET('common.locked', true);
console.log($('input').prop('disabled'), $('ui-component').hclass('ui-disabled'));
// logs: true true
</script>
```

### enabled:expression

Type: `command`

Enables the form controls and the components inside the target when the result is truthy, and disables them otherwise.

Example: Enable a button
```html
<ui-bind path="common.valid" config="enabled"><button>Save</button></ui-bind>

<script>
console.log($('button').prop('disabled'));
// logs: true
SET('common.valid', true);
console.log($('button').prop('disabled'));
// logs: false
</script>
```

### required:expression

Type: `command`

Sets the `required` config key of the components inside the target.

Example: Require a field
```html
<ui-bind path="common.company" config="required"><ui-component name="field"></ui-component></ui-bind>

<script>
COMPONENT('field', function(self) {});

SET('common.company', true);
console.log($('ui-component').component().config.required);
// logs: true
</script>
```

### assign:path

Type: `command`

Writes the instance of the binder to a path.

The instance has the method `exec(value, path, [flags])`, which runs the commands with a given value.

Example: Run the commands from code
```html
<ui-bind path="common.name" config="text;assign:common.binder"></ui-bind>

<script>
common.binder.exec('Manual', 'common.name');
console.log($('ui-bind').text());
// logs: Manual
</script>
```

### once

Type: `command`

Runs the commands only one time.

With the `!` prefix in the path, the commands run for the first value that is not empty. Without it, they run with the value that exists when the element is created.

Example: Render the first value
```html
<ui-bind path="!common.name" config="once;text"></ui-bind>

<script>
SET('common.name', 'first');
SET('common.name', 'second');
console.log($('ui-bind').text());
// logs: first
</script>
```

### strict

Type: `command`

Ignores changes made in nested paths.

Example: React only to the path itself
```html
<ui-bind path="common.user" config="strict;text:value.name"></ui-bind>

<script>
SET('common.user', { name: 'Anna' });
SET('common.user.name', 'Peter');
console.log($('ui-bind').text());
// logs: Anna
</script>
```

### track:name[,name]

Type: `command`

Limits changes in nested paths to the listed property names.

A change of the observed path itself, or of a parent path, always runs the commands.

Example: Track one property
```html
<ui-bind path="common.user" config="track:name;text:value.name + ' ' + value.age"></ui-bind>

<script>
SET('common.user.age', 30);
console.log($('ui-bind').text());
// logs: Anna 20
SET('common.user.name', 'Peter');
console.log($('ui-bind').text());
// logs: Peter 30
</script>
```

### changes

Type: `command`

Runs the commands only when the value differs from the previous one.

Example: Ignore identical values
```html
<ui-bind path="common.total" config="changes;exec:FUNC.log"></ui-bind>

<script>
FUNC.log = value => value && console.log(value);

SET('common.total', 1);
SET('common.total', 1);
SET('common.total', 2);
// logs: 1
// logs: 2
</script>
```

### check:path

Type: `command`

Runs the commands only when the function at the path returns a truthy value.

The function receives the value, the path and the `<ui-bind>` element.

Example: Filter the values
```html
<ui-bind path="common.age" config="check:FUNC.adult;text"></ui-bind>

<script>
FUNC.adult = value => value >= 18;

SET('common.age', 15);
console.log($('ui-bind').text() === '');
// logs: true
SET('common.age', 20);
console.log($('ui-bind').text());
// logs: 20
</script>
```

### delay:milliseconds

Type: `command`

Waits for the given time and runs the commands with the last value.

Without a value, the delay is 100 milliseconds.

Example: Group quick changes
```html
<ui-bind path="common.search" config="delay:50;text"></ui-bind>

<script>
SET('common.search', 'a');
SET('common.search', 'ab');
console.log($('ui-bind').text() === '');
// logs: true
setTimeout(() => console.log($('ui-bind').text()), 200);
// logs: ab
</script>
```
