---
title: ui-component
project: jComponent V20
version: 20.015
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/reference/ui-component/
updated: 2026-11-18T13:58:19.462Z
---

# ui-component

> The attributes and the config keys of the ui-component element.

The `<ui-component>` element places an instance of a component declared with `COMPONENT()` in the page. Its attributes are read once, when the element is created. The [Using components](../../guides/using-components/) guide explains how to work with it, and the instance itself is described on the [Component](../component/) page.

## API

### name="component"

Type: `property`

The name of the component declared with `COMPONENT()`. The attribute is required: an element without it is ignored.

When no declaration with this name exists, the library downloads one from the address in the `source` attribute, or from the address in `DEF.fallback`.

A name that starts with `LAZY ` (for example `LAZY dialog`) delays the creation of the instance until the first `SETTER()` call for that component.

Example: Create a component on the first SETTER() call
```html
<ui-component name="LAZY dialog"></ui-component>

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

// The instance does not exist yet. This call creates it and then runs show().
SETTER('dialog/show', 'Hello');
// logs: created
// logs: show Hello
</script>
```

### path="path"

Type: `property`

The path of the value that the component reads and writes.

The value is passed to the `setter` of the component and every change at the path calls it again. A `?` is replaced with the path of the parent plugin. Without this attribute, or with the value `null`, the component has no path. See [Paths](../../guides/paths/).

Example: Bind a component to a path
```html
<ui-component name="label" path="common.title"></ui-component>

<script>
COMPONENT('label', function(self) {
    self.setter = function(value) {
        self.text(value);
    };
});

SET('common.title', 'Hello');
console.log($('ui-component').text());
// logs: Hello
</script>
```

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

Type: `property`

The configuration of the instance.

Keys and values are separated with `:`, pairs with `;`. Write `\;` and `\:` to use these characters in a value. The values `true` and `false` become booleans and numeric values become numbers. Everything else stays a string.

The keys of the attribute overwrite the default configuration given to `COMPONENT()`.

Example: Read the configuration
```html
<ui-component name="box" config="title:Orders;limit:10;open:true;note:a\;b"></ui-component>

<script>
COMPONENT('box', 'limit:5;color:red', function(self, config) {
    console.log(JSON.stringify(config));
});
// logs: {"limit":10,"color":"red","title":"Orders","open":true,"note":"a;b"}
</script>
```

### default="expression"

Type: `property`

A JavaScript expression that gives the default value of the path.

The expression is evaluated when the component initializes and the value at the path is `null` or `undefined`. The result is written to the path without calling the `setter` a second time. It is evaluated again when a notification with the `@default` flag finds an empty value.

Example: Fill an empty path
```html
<ui-component name="field" path="common.count" default="10"></ui-component>
<ui-component name="field" path="common.tags" default="['a', 'b']"></ui-component>

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

console.log(common.count, common.tags.join());
// logs: 10 a,b
</script>
```

### source="URL"

Type: `property`

The address of the declaration, used when the component is not declared in the page.

The content at the address is imported once for all elements with the same name, and the waiting instances are created afterwards.

Example: Load the declaration from your own server
```html
<ui-component name="clock" source="/components/clock.html"></ui-component>
```

### plugin="path"

Type: `property`

Creates a plugin on the element itself.

The value has the same form as the `path` attribute of [ui-plugin](../ui-plugin/). The plugin is created first, and a `?` in the path of the component refers to it.

Example: A component with its own plugin
```html
<ui-component name="total" plugin="orders" path="?.sum"></ui-component>

<script>
PLUGIN('orders', function(exports) {
    exports.make = function() {
        exports.set('sum', 25);
    };
});

COMPONENT('total', function(self) {
    self.setter = function(value) {
        self.text(value);
    };
    self.make = function() {
        console.log(self.path.toString(), self.plugin.name);
    };
});
// logs: orders.sum orders
</script>
```

### $assign:path

Type: `config`

Writes the component instance to a path.

Example: Keep a reference to the instance
```html
<ui-component name="grid" config="$assign:common.grid"></ui-component>

<script>
COMPONENT('grid', function(self) {
    self.reload = () => console.log('reloaded');
});

common.grid.reload();
// logs: reloaded
</script>
```

### $class:name

Type: `config`

Toggles a CSS class on the element when the component is configured.

Example: Add a class once the component is ready
```html
<ui-component name="panel" config="$class:ready"></ui-component>

<script>
COMPONENT('panel', function(self) {});
</script>
```

### $id:value

Type: `config`

Sets the `id` of the instance.

The identifier selects the component in `SETTER('#value/method')` and `CONFIG('#value', ...)`.

Example: Call one instance by its identifier
```html
<ui-component name="tab" config="$id:first"></ui-component>
<ui-component name="tab" config="$id:second"></ui-component>

<script>
COMPONENT('tab', function(self) {
    self.open = () => console.log('open', self.id);
});

SETTER('#second/open');
// logs: open second
</script>
```

### $init:path

Type: `config`

Calls a function when the component is configured.

The function receives the instance. A `?` in the value is replaced with the path of the parent plugin.

Example: Run a function with the instance
```html
<ui-component name="chart" config="$init:FUNC.chartready"></ui-component>

<script>
FUNC.chartready = function(component) {
    console.log(component.name);
};

COMPONENT('chart', function(self) {});
// logs: chart
</script>
```

### $setter:path

Type: `config`

Calls a function after each change of the value.

The function receives `value`, `path` and `flags`, the same arguments as the `setter` delegate.

Example: Observe the value from outside
```html
<ui-component name="input" path="common.name" config="$setter:FUNC.changed"></ui-component>

<script>
FUNC.changed = function(value, path) {
    value && console.log(path, value);
};

COMPONENT('input', function(self) {});

SET('common.name', 'Peter');
// logs: common.name Peter
</script>
```

### =key:path

Type: `config`

Keeps the config key `key` equal to the value at a path.

The key is set when the component initializes and on each change at the path. `configure` is called each time.

Example: Drive a config key from the model
```html
<ui-component name="list" config="=limit:common.limit"></ui-component>

<script>
COMPONENT('list', function(self) {
    self.configure = function(key, value) {
        key === 'limit' && value && console.log('limit', value);
    };
});

SET('common.limit', 50);
// logs: limit 50
</script>
```

### =:path

Type: `config`

Applies the object at a path as the configuration.

Each key of the object is set with `reconfigure()` when the component initializes and on each change at the path. The path must contain an object when the component initializes.

Example: Configure a component from an object
```html
<ui-component name="list" config="=:common.options"></ui-component>

<script>
var common = { options: { limit: 10 } };

COMPONENT('list', function(self, config) {
    self.make = () => setTimeout(() => console.log(config.limit), 50);
});
// logs: 10
</script>
```

### type:name

Type: `config`

Converts the value that the component writes with `getter()`.

Supported values are `number`, `currency`, `float`, `boolean`, `bool`, `date` and `datetime`. Any other value leaves the input unchanged.

Example: Store a number
```html
<ui-component name="amount" path="common.price" config="type:number"><input /></ui-component>

<script>
COMPONENT('amount', function(self) {
    self.make = () => self.autobind20();
});

$('input').val('1 250.5').trigger('change');
setTimeout(() => console.log(common.price, typeof(common.price)), 300);
// logs: 1250.5 number
</script>
```

### format:value

Type: `config`

The date format used to parse the input when `type` is `date` or `datetime`.

Without this key, the format in `DEF.dateformat` is used.

Example: Parse a custom date format
```html
<ui-component name="date" path="common.date" config="type:date;format:dd.MM.yyyy"><input /></ui-component>

<script>
COMPONENT('date', function(self) {
    self.make = () => self.autobind20();
});

$('input').val('15.01.2024').trigger('change');
setTimeout(() => console.log(common.date.format('yyyy-MM-dd')), 300);
// logs: 2024-01-15
</script>
```

### touched:true

Type: `config`

Marks the component as touched and sets the `ui-touched` class on the element.

### modified:true

Type: `config`

Marks the component as modified and sets the `ui-modified` class on the element.

### invalid:true

Type: `config`

Marks the component as invalid and sets the `ui-invalid` class on the element.

The value is overwritten each time the component validates. When a `validate` delegate returns a string, the key holds that string.

### disabled:true

Type: `config`

Marks the component as disabled and sets the `ui-disabled` class on the element.

Example: State classes
```html
<ui-component name="field" config="disabled:true;touched:true"></ui-component>

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

### required:true

Type: `config`

Marks the component as required.

The key is set by the `required` command of [ui-bind](../ui-bind/) and is matched by the `@required` flag when components are searched by path. A component reads it in its own code.
