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

# ui-component

> Los atributos, las claves de configuración, los métodos y las clases CSS del elemento ui-component.

El elemento `<ui-component>` coloca en la página un componente declarado con `COMPONENT()`. Sus atributos seleccionan el componente, lo enlazan a un path y lo configuran. En [Usar componentes](../../guides/using-components/) se explica cómo trabajar con el elemento, y la instancia que crea se describe en [Componente](../component/).

## API

### name="component"

Type: `property`

Selecciona el componente que se va a crear.

El atributo admite estas formas:

| Valor | Significado |
| --- | --- |
| `box` | El componente declarado como `box`. |
| `box@2` | El componente declarado como `box@2`. |
| `box\|panel` | El primero de los componentes indicados que esté declarado. |
| `box,panel` | Una instancia de cada componente en el mismo elemento. |
| `lazy box` | La instancia se crea en la primera llamada a `SETTER()` para `box`. |

Un elemento sin `name` se ignora.

Example: Un componente enlazado a un 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: Gana el primer componente declarado
```html
<ui-component name="missing|hello"></ui-component>

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

Example: Un componente lazy
```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`

Enlaza el componente a un path del modelo de datos.

El valor del path se pasa al delegate [`setter`](../component/#setter). El atributo admite estas formas:

| Valor | Significado |
| --- | --- |
| `form.name` | Un path absoluto. |
| `?.name` | Un path relativo al [`ui-plugin`](../ui-plugin/) más cercano. |
| `?` | El path del `<ui-plugin>` más cercano. |
| `*name` | Un path dentro de `DEF.pathcommon`, que de forma predeterminada es `common.`. |
| `%name` | Un path temporal. |
| `@key` | Lee el valor guardado con [`data()`](../component/#data) del componente padre. |
| `form.name --> expression` | Transforma el valor con una expresión que recibe `value`. |

Un componente sin `path` no está enlazado al modelo de datos. Encontrarás más sobre la sintaxis en [Paths](../../guides/paths/).

Example: Formas del 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: Transformar el valor
```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: Leer datos del componente padre
```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`

Define la configuración inicial de la instancia.

El valor es una lista de pares `key:value` separados por punto y coma. Los números y los booleanos se convierten a sus tipos. El atributo se lee una sola vez, al crear la instancia. Para cambiar la configuración más adelante, llama a [`reconfigure()`](#reconfigure).

La configuración se combina en este orden: el valor predeterminado de `COMPONENT()`, este atributo y, por último, las reglas de `CONFIG()`.

Example: Valores con tipo
```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`

Una clave que empieza por `=` lee su valor de un path y sigue sus cambios.

El valor de `=key:path` se lee del path. Cuando el path cambia, la instancia recibe el nuevo valor a través del delegate [`configure`](../component/#configure).

Example: Una clave observada
```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`

Un valor que empieza por `=` y no tiene dos puntos carga toda la configuración desde un path.

El path debe contener un objeto. La instancia se reconfigura cada vez que cambia el path.

Example: Leer un objeto
```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`

Un valor que empieza por `%` usa una variable global como objeto de configuración.

La instancia trabaja directamente con el objeto guardado en `window`.

Example: Usar un objeto global
```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`

Un valor puede variar según el tamaño de pantalla o la apariencia clara u oscura.

Escribe las alternativas como `@name=value` separadas por comas. Los nombres son `xs`, `sm`, `md`, `lg`, `dark` y `light`. Se usa el valor que coincide con la pantalla actual. Si el tamaño actual no tiene valor, se usa el tamaño definido más cercano.

Example: Un valor por tamaño de pantalla
```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`

Define el identificador de la instancia.

El identificador se guarda en [`id`](../component/#id) y se puede usar en selectores como `#users`.

Example: Buscar una instancia por su identificador
```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`

Define el tipo de datos de la instancia.

El tipo se guarda en [`type`](../component/#type) y se pasa a los parsers y formatters.

Example: Definir el tipo
```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`

Alterna clases CSS en el elemento.

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

### $assign:path

Type: `config`

Escribe la instancia en un path.

El path se pone a `null` cuando se destruye la instancia.

Example: Conservar una referencia
```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`

Llama a una función cuando la instancia está lista.

La función recibe la instancia, y `this` también es la instancia.

Example: Una función de inicialización
```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`

Llama a una función cada vez que la instancia recibe un valor.

La función recibe `value`, `path` y `type`, y `this` es la instancia.

Example: Observar los valores
```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`

Llama a una función cada vez que cambia el estado de la instancia.

La función recibe `type` y `what`, los mismos argumentos que el delegate [`state`](../component/#state).

Example: Observar el estado
```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`

Mantiene el path fuera del `<ui-plugin>` más cercano.

El carácter `?` del path no se sustituye.

Example: Ignorar el 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`

Retrasa los valores hasta que el elemento sea visible.

Tiene el mismo efecto que llamar a [`bindvisible()`](../component/#bindvisible) en la declaración.

Example: Esperar a que el elemento sea visible
```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`

Importa el componente cuando no está declarado.

La URL se pasa a `IMPORT()`. Se ejecuta una vez por URL.

Example: Importar un componente que falta
```html
<ui-component name="remote" config="$url:/components/remote.html"></ui-component>
```

### $realtime:false

Type: `config`

Determina cuándo escribe su valor un input con `data-jc-bind`.

Con `true`, el valor se escribe mientras el usuario teclea. Con `false`, se escribe en el evento `change`.

Example: Escribir al cambiar
```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`

Define el retardo del binding en tiempo real en milisegundos.

El valor predeterminado es `DEF.delaykeypress`, que es `200`.

Example: Un retardo más corto
```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`

Define el valor predeterminado del path.

El atributo contiene una expresión de JavaScript. El valor se escribe cuando el path es `undefined`, y [`default()`](../component/#default) lo restaura.

Example: Un valor predeterminado
```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`

Crea un scope directamente en el elemento.

El valor es el path del scope. Funciona como envolver el elemento en un [`ui-plugin`](../ui-plugin/).

Example: Un scope en el elemento
```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`

Define el path y tiene prioridad sobre el atributo `path`.

Example: Sobrescribir el 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`

Define la configuración y tiene prioridad sobre el atributo `config`.

Example: Sobrescribir la configuración
```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`

Alterna clases CSS cuando la instancia está lista.

Separa varias clases con un espacio.

Example: Una clase añadida después de la inicialización
```html
<ui-component name="box" data-jc-class="ready"></ui-component>
<script>COMPONENT('box', function(self) {});</script>
```

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

Type: `property`

Mantiene el path fuera del `<ui-plugin>` más cercano.

Tiene el mismo efecto que la clave [`$noscope`](#x-noscope).

Example: Ignorar el 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`

Devuelve el valor del path enlazado.

Returns: `Object` El valor del path.

Example: Leer el valor
```js
var element = document.querySelector('ui-component');
console.log(element.get());  // Peter
```

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

Type: `method`

Escribe un valor en el path enlazado.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | El nuevo valor. |
| `type` | `Number` | no |  | El tipo de la actualización que se pasa al setter. |

La instancia se marca como modificada.

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

### element.update([type])

Type: `method`

Notifica al path enlazado con su valor actual.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `Number` | no |  | El tipo de la actualización que se pasa al setter. |

La instancia se marca como modificada.

Example: Refrescar después de un cambio directo
```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`

Escribe un valor a través de los parsers de la instancia.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | El nuevo valor. |
| `type` | `Number` | no | `2` | El tipo de la actualización. |

Llama a [`modify()`](../component/#modify) de la instancia.

Example: Escribir un valor analizado
```js
var element = document.querySelector('ui-component');
element.modify('  Anna  ');
console.log(GET('form.name'));  // Anna
```

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

Type: `method`

Cambia la configuración de la instancia.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Object` | no |  | La configuración nueva. |
| `init` | `Boolean` | no |  | Pasa `init` al delegate `configure`. |
| `noemit` | `Boolean` | no |  | Omite el delegate `configure`. |

Sin valor, el método vuelve a leer el atributo `config`.

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

### element.reset()

Type: `method`

Limpia el estado inválido y modificado de la instancia.

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

### element.config

Type: `property`

El objeto de configuración de la instancia.

La propiedad existe cuando la instancia ya se ha creado.

Example: Leer la configuración
```js
var element = document.querySelector('ui-component');
console.log(element.config.title);  // Orders
```

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

Type: `delegate`

Una función en el elemento del DOM que recibe cada valor.

Asígnala al elemento. Se ejecuta después del delegate `setter` de la instancia, con los mismos argumentos.

Example: Observar los valores desde fuera
```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`

Una función en el elemento del DOM que se ejecuta cuando cambia el estado.

La función recibe el objeto de configuración de la instancia.

Example: Observar el estado desde fuera
```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`

Una función en el elemento del DOM que recibe los cambios de configuración.

La función recibe los mismos argumentos que el delegate [`configure`](../component/#configure).

Example: Observar la configuración
```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`

Un evento de jQuery que se dispara en el elemento cuando la instancia está lista.

El evento se dispara una sola vez.

Example: Esperar a la instancia
```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`

Presente mientras el valor de la instancia está modificado.

Refleja `config.modified`.

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

### .ui-touched

Type: `class`

Presente después de que el usuario haya interactuado con la instancia.

Refleja `config.touched`.

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

### .ui-invalid

Type: `class`

Presente mientras el valor de la instancia es inválido.

Refleja `config.invalid`, que define el delegate [`validate`](../component/#validate).

Example: La clase 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`

Presente mientras la instancia está desactivada.

Refleja `config.disabled`. El comando [`disabled`](../ui-bind/#disabled) de `<ui-bind>` define la clave.

Example: La clase 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>
```
