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

# ui-component

> The attributes, configuration keys, methods and CSS classes of the ui-component element.

The `<ui-component>` element places a component declared with `COMPONENT()` in the page. Its attributes select the component, bind it to a path and configure it. [Using components](../../guides/using-components/) explains how to work with the element, and the instance it creates is described in [Component](../component/).

## API

### name="component"

Type: `property`

Selects the component to create.

The attribute accepts these forms:

| Value | Meaning |
| --- | --- |
| `box` | The component declared as `box`. |
| `box@2` | The component declared as `box@2`. |
| `box\|panel` | The first of the listed components that is declared. |
| `box,panel` | One instance of each component on the same element. |
| `lazy box` | The instance is created on the first `SETTER()` call for `box`. |

An element without `name` is ignored.

Example: A component bound to a path
```html
<ui-component name="hello" path="common.user"></ui-component>

<script>
    COMPONENT('hello', function(self) {
        self.setter = function(value) {
            self.text('Hello ' + value);
        };
    });
    SET('common.user', 'Peter');
</script>
```

Example: The first declared component wins
```html
<ui-component name="missing|hello"></ui-component>

<script>
    COMPONENT('hello', function(self) {
        console.log(self.name);  // hello
    });
</script>
```

Example: A lazy component
```html
<ui-component name="lazy dialog"></ui-component>

<script>
    COMPONENT('dialog', function(self) {
        self.show = function(title) {
            console.log('show', title);  // show Welcome
        };
    });

    // The first SETTER() call creates the instance
    setTimeout(() => SETTER('dialog/show', 'Welcome'), 500);
</script>
```

### path="path"

Type: `property`

Binds the component to a path of the data model.

The value of the path is passed to the [`setter`](../component/#setter) delegate. The attribute accepts these forms:

| Value | Meaning |
| --- | --- |
| `form.name` | An absolute path. |
| `?.name` | A path relative to the closest [`ui-plugin`](../ui-plugin/). |
| `?` | The path of the closest `<ui-plugin>`. |
| `*name` | A path inside `DEF.pathcommon`, which is `common.` by default. |
| `%name` | A temporary path. |
| `@key` | Reads the value stored with [`data()`](../component/#data) of the parent component. |
| `form.name --> expression` | Transforms the value with an expression that receives `value`. |

A component without `path` is not bound to the data model. More about the syntax is in [Paths](../../guides/paths/).

Example: Path forms
```html
<ui-plugin path="users">
    <ui-component name="show" path="?.name"></ui-component>
</ui-plugin>
<ui-component name="show" path="*title"></ui-component>

<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('show', function(self) {
        console.log(self.path);
    });
</script>
```

Example: Transforming the value
```html
<ui-component name="upper" path="form.name --> (value || '').toUpperCase()"></ui-component>

<script>
    COMPONENT('upper', function(self) {
        self.setter = function(value) {
            self.text(value);
        };
    });
    SET('form.name', 'peter');
</script>
```

Example: Reading data of the parent component
```html
<ui-component name="card">
    <ui-component name="label" path="@title"></ui-component>
</ui-component>

<script>
    COMPONENT('card', function(self) {
        self.make = function() {
            self.data('title', 'Orders');
        };
    });
    COMPONENT('label', function(self) {
        self.setter = function(value) {
            self.text(value);
        };
    });
    setTimeout(() => FIND('card').data('title', 'Invoices'), 500);
</script>
```

### config="key:value;key:value"

Type: `property`

Sets the initial configuration of the instance.

The value is a list of `key:value` pairs separated by semicolons. Numbers and booleans are converted to their types. The attribute is read once, when the instance is created. To change the configuration later, call [`reconfigure()`](#reconfigure).

The configuration is merged in this order: the default of `COMPONENT()`, this attribute and then the rules of `CONFIG()`.

Example: Typed values
```html
<ui-component name="box" config="title:Orders;limit:10;visible:true"></ui-component>

<script>
    COMPONENT('box', 'limit:5;color:red', function(self, config) {
        console.log(config.title, config.limit, config.visible, config.color);  // Orders 10 true red
    });
</script>
```

### config="=key:path"

Type: `type`

A key that starts with `=` reads its value from a path and follows its changes.

The value of `=key:path` is read from the path. When the path changes, the instance receives the new value through the [`configure`](../component/#configure) delegate.

Example: A watched key
```html
<ui-component name="box" config="=title:common.title"></ui-component>

<script>
    SET('common.title', 'First');
    COMPONENT('box', function(self, config) {
        self.configure = function(key, value) {
            key === 'title' && self.text(value);
        };
    });
    setTimeout(() => SET('common.title', 'Second'), 500);
</script>
```

### config="=path"

Type: `type`

A value that starts with `=` and has no colon loads the whole configuration from a path.

The path must contain an object. The instance is reconfigured each time the path changes.

Example: Reading an object
```html
<ui-component name="box" config="=common.options"></ui-component>

<script>
    SET('common.options', { title: 'Orders' });
    COMPONENT('box', function(self, config) {
        self.configure = function(key, value) {
            key === 'title' && self.text(value);
        };
    });
    setTimeout(() => SET('common.options', { title: 'Invoices' }), 500);
</script>
```

### config="%variable"

Type: `type`

A value that starts with `%` uses a global variable as the configuration object.

The instance works directly with the object stored in `window`.

Example: Using a global object
```html
<ui-component name="box" config="%boxoptions"></ui-component>

<script>
    window.boxoptions = { title: 'Orders' };
    COMPONENT('box', function(self, config) {
        console.log(config.title, config === window.boxoptions);  // Orders true
    });
</script>
```

### config="key:@xs=value,@lg=value"

Type: `type`

A value can differ per display size or per light and dark appearance.

Write the alternatives as `@name=value` separated by commas. The names are `xs`, `sm`, `md`, `lg`, `dark` and `light`. The value that matches the current display is used. If the current size has no value, the closest defined size is used.

Example: A value per display size
```html
<ui-component name="grid" config="columns:@xs=1,@sm=2,@md=3,@lg=4"></ui-component>

<script>
    COMPONENT('grid', function(self, config) {
        console.log(WIDTH(), config.columns);  // xs 1
    });
</script>
```

### $id:identifier

Type: `config`

Sets the identifier of the instance.

The identifier is stored in [`id`](../component/#id) and can be used in selectors such as `#users`.

Example: Finding an instance by its identifier
```html
<ui-component name="box" config="$id:users"></ui-component>

<script>
    COMPONENT('box', function(self) {});
    setTimeout(() => console.log(FIND('#users').name), 500);  // box
</script>
```

### $type:type

Type: `config`

Sets the data type of the instance.

The type is stored in [`type`](../component/#type) and is passed to parsers and formatters.

Example: Setting the type
```html
<ui-component name="box" config="$type:number"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.make = () => console.log(self.type);  // number
    });
</script>
```

### $class:classes

Type: `config`

Toggles CSS classes on the element.

Example: Adding a class
```html
<ui-component name="box" config="$class:highlighted"></ui-component>
<script>COMPONENT('box', function(self) {});</script>
```

### $assign:path

Type: `config`

Writes the instance to a path.

The path is set to `null` when the instance is destroyed.

Example: Keeping a reference
```html
<ui-component name="box" config="$assign:common.box"></ui-component>

<script>
    COMPONENT('box', function(self) {});
    setTimeout(() => console.log(GET('common.box').name), 500);  // box
</script>
```

### $init:path

Type: `config`

Calls a function when the instance is ready.

The function receives the instance, and `this` is the instance too.

Example: An initialization function
```html
<ui-component name="box" config="$init:common.onbox"></ui-component>

<script>
    window.common = { onbox: instance => console.log('ready', instance.name) };  // ready box
    COMPONENT('box', function(self) {});
</script>
```

### $setter:path

Type: `config`

Calls a function each time the instance receives a value.

The function receives `value`, `path` and `type`, and `this` is the instance.

Example: Observing values
```html
<ui-component name="box" path="form.name" config="$setter:common.onvalue"></ui-component>

<script>
    window.common = { onvalue: value => value && console.log(value) };  // Peter
    COMPONENT('box', function(self) {
        self.setter = function() {};
    });
    SET('form.name', 'Peter');
</script>
```

### $state:path

Type: `config`

Calls a function each time the state of the instance changes.

The function receives `type` and `what`, the same arguments as the [`state`](../component/#state) delegate.

Example: Observing the state
```html
<ui-component name="box" config="$state:common.onstate"></ui-component>

<script>
    window.common = { onstate: (type, what) => console.log(type, what) };  // 0 3
    COMPONENT('box', function(self) {});
</script>
```

### $noscope:true

Type: `config`

Keeps the path outside the closest `<ui-plugin>`.

The `?` character in the path is not replaced.

Example: Ignoring the scope
```html
<ui-plugin path="users">
    <ui-component name="box" path="?.name" config="$noscope:true"></ui-component>
</ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', function(self) {
        console.log(self.path);  // ?.name
    });
</script>
```

### $bindvisible:true

Type: `config`

Delays values until the element is visible.

It has the same effect as calling [`bindvisible()`](../component/#bindvisible) in the declaration.

Example: Waiting for a visible element
```html
<div id="tab" style="display:none">
    <ui-component name="box" path="form.name" config="$bindvisible:true"></ui-component>
</div>

<script>
    COMPONENT('box', function(self) {
        self.setter = function(value) {
            value && console.log('received', value);  // received Peter
        };
    });
    SET('form.name', 'Peter');
    setTimeout(() => $('#tab').show(), 500);
</script>
```

### $url:url

Type: `config`

Imports the component when it is not declared.

The URL is passed to `IMPORT()`. It runs once per URL.

Example: Importing a missing component
```html
<ui-component name="remote" config="$url:/components/remote.html"></ui-component>
```

### $realtime:false

Type: `config`

Selects when an input with `data-jc-bind` writes its value.

With `true` the value is written while the user types. With `false` it is written on the `change` event.

Example: Writing on change
```html
<ui-component name="box" path="form.name" config="$realtime:false">
    <input data-jc-bind />
</ui-component>

<script>
    COMPONENT('box', function(self) {});
    setTimeout(function() {
        var input = $('input').val('Peter').trigger('input');
        setTimeout(function() {
            console.log(GET('form.name') || 'empty');  // empty
            input.trigger('change');
            console.log(GET('form.name'));  // Peter
        }, 300);
    }, 500);
</script>
```

### $delay:milliseconds

Type: `config`

Sets the delay of realtime binding in milliseconds.

The default value is `DEF.delaykeypress`, which is `200`.

Example: A shorter delay
```html
<ui-component name="box" path="form.name" config="$delay:20">
    <input data-jc-bind />
</ui-component>

<script>
    COMPONENT('box', function(self) {});
    setTimeout(function() {
        $('input').val('Peter').trigger('input');
        setTimeout(() => console.log(GET('form.name')), 60);  // Peter
    }, 500);
</script>
```

### default="expression"

Type: `property`

Sets the default value of the path.

The attribute contains a JavaScript expression. The value is written when the path is `undefined`, and [`default()`](../component/#default) restores it.

Example: A default value
```html
<ui-component name="box" path="form.name" default="'Anonymous'"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.setter = function() {};
    });
    setTimeout(() => console.log(GET('form.name')), 500);  // Anonymous
</script>
```

### plugin="path"

Type: `property`

Creates a scope directly on the element.

The value is the path of the scope. It works like wrapping the element in a [`ui-plugin`](../ui-plugin/).

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

<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', function(self) {
        console.log(self.path);  // users.name
    });
</script>
```

### data-jc-path="path"

Type: `property`

Sets the path and takes priority over the `path` attribute.

Example: Overriding the path
```html
<ui-component name="box" path="form.a" data-jc-path="form.b"></ui-component>

<script>
    COMPONENT('box', function(self) {
        console.log(self.path);  // form.b
    });
</script>
```

### data-jc-config="key:value"

Type: `property`

Sets the configuration and takes priority over the `config` attribute.

Example: Overriding the configuration
```html
<ui-component name="box" config="title:A" data-jc-config="title:B"></ui-component>

<script>
    COMPONENT('box', function(self, config) {
        console.log(config.title);  // B
    });
</script>
```

### data-jc-class="classes"

Type: `property`

Toggles CSS classes when the instance is ready.

Separate several classes with a space.

Example: A class added after the initialization
```html
<ui-component name="box" data-jc-class="ready"></ui-component>
<script>COMPONENT('box', function(self) {});</script>
```

### data-jc-noscope="true"

Type: `property`

Keeps the path outside the closest `<ui-plugin>`.

It has the same effect as the [`$noscope`](#x-noscope) key.

Example: Ignoring the scope
```html
<ui-plugin path="users">
    <ui-component name="box" path="?.name" data-jc-noscope="true"></ui-component>
</ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', function(self) {
        console.log(self.path);  // ?.name
    });
</script>
```

### element.get()

Type: `method`

Returns the value of the bound path.

Returns: `Object` The value of the path.

Example: Reading the value
```js
var element = document.querySelector('ui-component');
console.log(element.get());  // Peter
```

### element.set(value, [type])

Type: `method`

Writes a value to the bound path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The new value. |
| `type` | `Number` | no |  | The type of the update passed to the setter. |

The instance is marked as modified.

Example: Writing a value
```js
var element = document.querySelector('ui-component');
element.set('Anna');
console.log(GET('form.name'));  // Anna
```

### element.update([type])

Type: `method`

Notifies the bound path with its current value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `Number` | no |  | The type of the update passed to the setter. |

The instance is marked as modified.

Example: Refreshing after a direct change
```js
var element = document.querySelector('ui-component');
window.form.name = 'Anna';
element.update();
setTimeout(() => console.log(element.textContent), 50);  // Anna
```

### element.modify(value, [type])

Type: `method`

Writes a value through the parsers of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The new value. |
| `type` | `Number` | no | `2` | The type of the update. |

It calls [`modify()`](../component/#modify) of the instance.

Example: Writing a parsed value
```js
var element = document.querySelector('ui-component');
element.modify('  Anna  ');
console.log(GET('form.name'));  // Anna
```

### element.reconfigure([value], [init], [noemit])

Type: `method`

Changes the configuration of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Object` | no |  | The new configuration. |
| `init` | `Boolean` | no |  | Passes `init` to the `configure` delegate. |
| `noemit` | `Boolean` | no |  | Skips the `configure` delegate. |

Without a value, the method reads the `config` attribute again.

Example: Changing a key
```js
var element = document.querySelector('ui-component');
element.reconfigure('title:Invoices');
console.log(element.config.title);  // Invoices
```

### element.reset()

Type: `method`

Clears the invalid and modified state of the instance.

Example: Clearing the state
```js
var element = document.querySelector('ui-component');
element.set('Anna');
element.reset();
console.log(element.config.modified);  // false
```

### element.config

Type: `property`

The configuration object of the instance.

The property exists when the instance has been created.

Example: Reading the configuration
```js
var element = document.querySelector('ui-component');
console.log(element.config.title);  // Orders
```

### element.setter = function(value, path, type)

Type: `delegate`

A function on the DOM element that receives each value.

Assign it to the element. It runs after the `setter` delegate of the instance with the same arguments.

Example: Observing values from outside
```js
var element = document.querySelector('ui-component');
element.setter = function(value, path, type) {
    console.log(value, path, type);  // Anna form.name 1
};
SET('form.name', 'Anna');
```

### element.state = function(config)

Type: `delegate`

A function on the DOM element that runs when the state changes.

The function receives the configuration object of the instance.

Example: Observing the state from outside
```js
var element = document.querySelector('ui-component');
element.state = function(config) {
    console.log(config.touched);  // true
};
FIND('demo').bind('touched');
```

### element.configure = function(key, value, init, prev)

Type: `delegate`

A function on the DOM element that receives configuration changes.

The function receives the same arguments as the [`configure`](../component/#configure) delegate.

Example: Observing the configuration
```js
var element = document.querySelector('ui-component');
element.configure = function(key, value, init, prev) {
    console.log(key, value, prev);  // title Invoices Orders
};
element.reconfigure('title:Invoices');
```

### $(element).on('component', callback)

Type: `event`

A jQuery event triggered on the element when the instance is ready.

The event is triggered once.

Example: Waiting for the instance
```html
<ui-component name="box" id="box"></ui-component>

<script>
    COMPONENT('box', function(self) {});
    $('#box').on('component', () => console.log('ready'));  // ready
</script>
```

### .ui-modified

Type: `class`

Present while the value of the instance is modified.

It follows `config.modified`.

Example: The modified class
```js
var com = FIND('demo');
com.bind('modified');
console.log(com.element.hclass('ui-modified'));  // true
```

### .ui-touched

Type: `class`

Present after the user has interacted with the instance.

It follows `config.touched`.

Example: The touched class
```js
var com = FIND('demo');
com.bind('touched');
console.log(com.element.hclass('ui-touched'));  // true
```

### .ui-invalid

Type: `class`

Present while the value of the instance is invalid.

It follows `config.invalid`, which is set by the [`validate`](../component/#validate) delegate.

Example: The invalid class
```html
<ui-component name="box" path="form.name"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.validate = value => !!value;
    });
</script>
```

### .ui-disabled

Type: `class`

Present while the instance is disabled.

It follows `config.disabled`. The [`disabled`](../ui-bind/#disabled) command of `<ui-bind>` sets the key.

Example: The disabled class
```html
<ui-bind path="form.locked" config="disabled:value">
    <ui-component name="box"></ui-component>
</ui-bind>

<script>
    COMPONENT('box', function(self) {});
    SET('form.locked', true);
</script>
```
