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

# ui-component

> Atribúty, konfiguračné kľúče, metódy a triedy CSS elementu ui-component.

Element `<ui-component>` umiestni na stránku komponent deklarovaný pomocou `COMPONENT()`. Jeho atribúty vyberajú komponent, viažu ho na path a konfigurujú ho. Ako s elementom pracovať, vysvetľuje časť [Používanie komponentov](../../guides/using-components/) a inštanciu, ktorú vytvorí, popisuje časť [Komponent](../component/).

## API

### name="component"

Type: `property`

Vyberie komponent, ktorý sa má vytvoriť.

Atribút prijíma tieto tvary:

| Hodnota | Význam |
| --- | --- |
| `box` | Komponent deklarovaný ako `box`. |
| `box@2` | Komponent deklarovaný ako `box@2`. |
| `box\|panel` | Prvý z uvedených komponentov, ktorý je deklarovaný. |
| `box,panel` | Jedna inštancia každého komponentu na tom istom elemente. |
| `lazy box` | Inštancia sa vytvorí pri prvom volaní `SETTER()` pre `box`. |

Element bez `name` sa ignoruje.

Example: Komponent viazaný na 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: Vyhráva prvý deklarovaný komponent
```html
<ui-component name="missing|hello"></ui-component>

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

Example: Lazy komponent
```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`

Naviaže komponent na path dátového modelu.

Hodnota na path sa odovzdá do delegate [`setter`](../component/#setter). Atribút prijíma tieto tvary:

| Hodnota | Význam |
| --- | --- |
| `form.name` | Absolútna path. |
| `?.name` | Path relatívna k najbližšiemu [`ui-plugin`](../ui-plugin/). |
| `?` | Path najbližšieho `<ui-plugin>`. |
| `*name` | Path v rámci `DEF.pathcommon`, čo je predvolene `common.`. |
| `%name` | Dočasná path. |
| `@key` | Prečíta hodnotu uloženú pomocou [`data()`](../component/#data) nadradeného komponentu. |
| `form.name --> expression` | Transformuje hodnotu výrazom, ktorý dostane `value`. |

Komponent bez `path` nie je viazaný na dátový model. Viac o syntaxi nájdeš v časti [Path](../../guides/paths/).

Example: Tvary path
```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: Transformácia hodnoty
```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: Čítanie údajov nadradeného komponentu
```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`

Nastaví počiatočnú konfiguráciu inštancie.

Hodnota je zoznam dvojíc `key:value` oddelených bodkočiarkami. Čísla a logické hodnoty sa prevedú na svoje typy. Atribút sa prečíta raz, pri vytvorení inštancie. Ak chceš konfiguráciu zmeniť neskôr, zavolaj [`reconfigure()`](#reconfigure).

Konfigurácia sa zlučuje v tomto poradí: predvolené hodnoty z `COMPONENT()`, tento atribút a potom pravidlá z `CONFIG()`.

Example: Typované hodnoty
```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`

Kľúč, ktorý sa začína na `=`, číta svoju hodnotu z path a sleduje jej zmeny.

Hodnota `=key:path` sa číta z path. Keď sa path zmení, inštancia dostane novú hodnotu cez delegate [`configure`](../component/#configure).

Example: Sledovaný kľúč
```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`

Hodnota, ktorá sa začína na `=` a nemá dvojbodku, načíta celú konfiguráciu z path.

Path musí obsahovať objekt. Inštancia sa prekonfiguruje pri každej zmene path.

Example: Čítanie objektu
```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`

Hodnota, ktorá sa začína na `%`, použije ako konfiguračný objekt globálnu premennú.

Inštancia pracuje priamo s objektom uloženým vo `window`.

Example: Použitie globálneho objektu
```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`

Hodnota sa môže líšiť podľa veľkosti displeja alebo podľa svetlého a tmavého vzhľadu.

Alternatívy zapíš ako `@name=value` oddelené čiarkami. Názvy sú `xs`, `sm`, `md`, `lg`, `dark` a `light`. Použije sa hodnota, ktorá zodpovedá aktuálnemu displeju. Ak aktuálna veľkosť nemá hodnotu, použije sa najbližšia definovaná veľkosť.

Example: Hodnota podľa veľkosti displeja
```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`

Nastaví identifikátor inštancie.

Identifikátor sa uloží do [`id`](../component/#id) a môžeš ho použiť v selektoroch, ako je `#users`.

Example: Vyhľadanie inštancie podľa identifikátora
```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`

Nastaví dátový typ inštancie.

Typ sa uloží do [`type`](../component/#type) a odovzdáva sa parserom a formátovačom.

Example: Nastavenie typu
```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`

Prepína triedy CSS na elemente.

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

### $assign:path

Type: `config`

Zapíše inštanciu na path.

Pri zničení inštancie sa path nastaví na `null`.

Example: Uchovanie odkazu
```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`

Zavolá funkciu, keď je inštancia pripravená.

Funkcia dostane inštanciu a aj `this` je inštancia.

Example: Inicializačná funkcia
```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`

Zavolá funkciu vždy, keď inštancia dostane hodnotu.

Funkcia dostane `value`, `path` a `type` a `this` je inštancia.

Example: Sledovanie hodnôt
```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`

Zavolá funkciu pri každej zmene stavu inštancie.

Funkcia dostane `type` a `what`, teda rovnaké argumenty ako delegate [`state`](../component/#state).

Example: Sledovanie stavu
```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`

Ponechá path mimo najbližšieho `<ui-plugin>`.

Znak `?` v path sa nenahrádza.

Example: Ignorovanie scopu
```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`

Odloží hodnoty, kým nebude element viditeľný.

Má rovnaký účinok ako volanie [`bindvisible()`](../component/#bindvisible) v deklarácii.

Example: Čakanie na viditeľný 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`

Importuje komponent, keď nie je deklarovaný.

URL sa odovzdá do `IMPORT()`. Spustí sa raz pre každú URL.

Example: Import chýbajúceho komponentu
```html
<ui-component name="remote" config="$url:/components/remote.html"></ui-component>
```

### $realtime:false

Type: `config`

Určuje, kedy vstupné pole s `data-jc-bind` zapíše svoju hodnotu.

Pri `true` sa hodnota zapisuje počas písania používateľa. Pri `false` sa zapíše pri udalosti `change`.

Example: Zápis pri zmene
```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`

Nastaví oneskorenie väzby v reálnom čase v milisekundách.

Predvolená hodnota je `DEF.delaykeypress`, čo je `200`.

Example: Kratšie oneskorenie
```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`

Nastaví predvolenú hodnotu path.

Atribút obsahuje výraz JavaScriptu. Hodnota sa zapíše, keď je path `undefined`, a [`default()`](../component/#default) ju obnoví.

Example: Predvolená hodnota
```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`

Vytvorí scope priamo na elemente.

Hodnota je path scopu. Funguje to, ako keby si element obalil do [`ui-plugin`](../ui-plugin/).

Example: Scope na elemente
```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`

Nastaví path a má prednosť pred atribútom `path`.

Example: Prepísanie 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`

Nastaví konfiguráciu a má prednosť pred atribútom `config`.

Example: Prepísanie konfigurácie
```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`

Prepne triedy CSS, keď je inštancia pripravená.

Viacero tried oddeľ medzerou.

Example: Trieda pridaná po inicializácii
```html
<ui-component name="box" data-jc-class="ready"></ui-component>
<script>COMPONENT('box', function(self) {});</script>
```

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

Type: `property`

Ponechá path mimo najbližšieho `<ui-plugin>`.

Má rovnaký účinok ako kľúč [`$noscope`](#x-noscope).

Example: Ignorovanie scopu
```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`

Vráti hodnotu na naviazanej path.

Returns: `Object` Hodnota na path.

Example: Čítanie hodnoty
```js
var element = document.querySelector('ui-component');
console.log(element.get());  // Peter
```

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

Type: `method`

Zapíše hodnotu na naviazanú path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Nová hodnota. |
| `type` | `Number` | no |  | Typ aktualizácie odovzdaný setteru. |

Inštancia sa označí ako upravená.

Example: Zápis hodnoty
```js
var element = document.querySelector('ui-component');
element.set('Anna');
console.log(GET('form.name'));  // Anna
```

### element.update([type])

Type: `method`

Upozorní naviazanú path s jej aktuálnou hodnotou.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `Number` | no |  | Typ aktualizácie odovzdaný setteru. |

Inštancia sa označí ako upravená.

Example: Obnovenie po priamej zmene
```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`

Zapíše hodnotu cez parsery inštancie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Nová hodnota. |
| `type` | `Number` | no | `2` | Typ aktualizácie. |

Volá [`modify()`](../component/#modify) inštancie.

Example: Zápis spracovanej hodnoty
```js
var element = document.querySelector('ui-component');
element.modify('  Anna  ');
console.log(GET('form.name'));  // Anna
```

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

Type: `method`

Zmení konfiguráciu inštancie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Object` | no |  | Nová konfigurácia. |
| `init` | `Boolean` | no |  | Odovzdá `init` do delegate `configure`. |
| `noemit` | `Boolean` | no |  | Preskočí delegate `configure`. |

Bez hodnoty metóda znova prečíta atribút `config`.

Example: Zmena kľúča
```js
var element = document.querySelector('ui-component');
element.reconfigure('title:Invoices');
console.log(element.config.title);  // Invoices
```

### element.reset()

Type: `method`

Vymaže stav neplatnosti a úpravy inštancie.

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

### element.config

Type: `property`

Konfiguračný objekt inštancie.

Vlastnosť existuje po vytvorení inštancie.

Example: Čítanie konfigurácie
```js
var element = document.querySelector('ui-component');
console.log(element.config.title);  // Orders
```

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

Type: `delegate`

Funkcia na elemente DOM, ktorá dostáva každú hodnotu.

Priraď ju elementu. Spustí sa po delegate `setter` inštancie s rovnakými argumentmi.

Example: Sledovanie hodnôt zvonka
```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`

Funkcia na elemente DOM, ktorá sa spustí pri zmene stavu.

Funkcia dostane konfiguračný objekt inštancie.

Example: Sledovanie stavu zvonka
```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`

Funkcia na elemente DOM, ktorá dostáva zmeny konfigurácie.

Funkcia dostane rovnaké argumenty ako delegate [`configure`](../component/#configure).

Example: Sledovanie konfigurácie
```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`

Udalosť jQuery vyvolaná na elemente, keď je inštancia pripravená.

Udalosť sa vyvolá raz.

Example: Čakanie na inštanciu
```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`

Je prítomná, kým je hodnota inštancie upravená.

Riadi sa hodnotou `config.modified`.

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

### .ui-touched

Type: `class`

Je prítomná po tom, ako používateľ s inštanciou interagoval.

Riadi sa hodnotou `config.touched`.

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

### .ui-invalid

Type: `class`

Je prítomná, kým je hodnota inštancie neplatná.

Riadi sa hodnotou `config.invalid`, ktorú nastavuje delegate [`validate`](../component/#validate).

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

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

### .ui-disabled

Type: `class`

Je prítomná, kým je inštancia zakázaná.

Riadi sa hodnotou `config.disabled`. Tento kľúč nastavuje príkaz [`disabled`](../ui-bind/#disabled) elementu `<ui-bind>`.

Example: Trieda disabled
```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>
```
