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

# Component

> The delegates, properties and methods of a component instance.

A component instance is the object passed to the declaration of `COMPONENT()`. It connects an element to a path of the data model. [Creating components](../../guides/creating-components/) explains how to write one, and [ui-component](../ui-component/) describes the element. In the examples, `com` is an instance found with `FIND()`.

## API

### self.make = function()

Type: `delegate`

Builds the content of the component.

The delegate runs once, after the declaration, when the element is in the DOM.

Example: Defining make
```html
<ui-component name="box"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.make = function() {
            self.html('<b>Ready</b>');
        };
    });
</script>
```

### self.init = function()

Type: `delegate`

Runs once for all instances of the component.

Only the first instance of the page calls this delegate.

Example: Defining init
```html
<ui-component name="box"></ui-component>
<ui-component name="box"></ui-component>

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

### self.done = function()

Type: `delegate`

Runs after the instance has been initialized.

The delegate runs after the first `setter` and `state` calls.

Example: Defining done
```html
<ui-component name="box"></ui-component>

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

### self.released = function(hidden)

Type: `delegate`

Tells whether the element is hidden when the instance starts.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `hidden` | `Boolean` | yes |  | `true` when the element is hidden. |

The delegate runs once and receives `true` for a hidden element.

Example: Defining released
```html
<ui-component name="box"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.released = hidden => console.log(hidden);  // false
    });
</script>
```

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

Type: `delegate`

Receives the configuration keys.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | The name of the key. |
| `value` | `Object` | yes |  | The new value. |
| `init` | `Boolean` | yes |  | `true` during the initialization. |
| `prev` | `Object` | yes |  | The previous value. |

The delegate runs for each key during the initialization, with `init` set to `true`, and again for each changed key. It also receives changes of the `modified`, `touched` and `invalid` keys.

Example: Defining configure
```html
<ui-component name="box" config="title:Orders"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.configure = function(key, value, init, prev) {
            key === 'title' && console.log(value, init);  // Orders true
        };
    });
</script>
```

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

Type: `delegate`

Receives the value of the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The value of the path. |
| `path` | `String` | yes |  | The path that changed. |
| `type` | `Number` | yes |  | The source of the change. |

Define it to render the value. The default implementation writes the formatted value to nested `input`, `select` and `textarea` fields with the `data-jc-bind` attribute.

The `type` argument tells where the change comes from:

| Type | Source |
| --- | --- |
| `0` | The initialization. |
| `1` | A manual change, such as `SET()`. |
| `2` | An input of the user. |
| `3` | A default value or a reset. |

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

<script>
    COMPONENT('box', function(self) {
        self.setter = function(value, path, type) {
            self.text(value);
        };
    });
    SET('form.name', 'Peter');
</script>
```

### self.getter(value, [realtime], [nobind])

Type: `delegate`

Writes a value from the user to the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The raw value. |
| `realtime` | `Boolean` | no |  | `true` when the value comes while the user types. |
| `nobind` | `Boolean` | no |  | `true` validates the value without writing it. |

The default implementation runs the parsers and writes the result. Nested fields with the `data-jc-bind` attribute call it automatically. Call it from your own controls to write a value.

Example: Defining getter
```html
<ui-component name="box" path="form.name"><button>Set</button></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.make = function() {
            self.event('click', 'button', () => self.getter('Peter'));
        };
    });
    setTimeout(function() {
        $('button').click();
        console.log(GET('form.name'));  // Peter
    }, 500);
</script>
```

### self.setter2 = function(value, path, type)

Type: `delegate`

Runs after the `setter` delegate.

It receives the same arguments. Use it to extend a component and keep its setter.

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

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

### self.getter2 = function(value, realtime)

Type: `delegate`

Runs when the `getter` receives a value.

It receives the parsed value and the `realtime` argument.

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

<script>
    COMPONENT('box', function(self) {
        self.getter2 = value => console.log(value);  // PETER
        self.parser((path, value) => value.toUpperCase());
    });
    setTimeout(() => FIND('box').getter('peter'), 500);
</script>
```

### self.state = function(type, what)

Type: `delegate`

Runs when the state of the instance changes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `Number` | yes |  | The source of the change. |
| `what` | `Number` | yes |  | The kind of the change. |

The `type` argument is `0` for the initialization, `1` for a manual change and `2` for an input of the user.

The `what` argument tells what happened:

| What | Meaning |
| --- | --- |
| `1` | Validation. |
| `2` | The touched state changed. |
| `3` | A reset. |
| `4` | An update. |
| `5` | A new value. |
| `6` | A notification. |

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

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

### self.state2 = function(type, what)

Type: `delegate`

Runs after the `state` delegate.

It receives the same arguments.

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

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

### self.validate = function(value, init)

Type: `delegate`

Decides whether the value is valid.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | The value of the path. |
| `init` | `Boolean` | no |  | `true` during the initialization. |

Return `true` for a valid value. The result is stored in `config.invalid`.

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

<script>
    COMPONENT('box', function(self, config) {
        self.validate = value => !!value;
        self.done = () => console.log(config.invalid);  // true
    });
</script>
```

### self.service = function(counter)

Type: `delegate`

Runs once per minute.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | The number of runs. |

The delegate receives a counter that grows by one on each run.

### self.destroy = function()

Type: `delegate`

Runs when the instance is removed.

Release timers and external listeners here.

Example: Defining destroy
```html
<ui-component name="box"></ui-component>

<script>
    COMPONENT('box', function(self) {
        self.destroy = () => console.log('destroyed');  // destroyed
    });
    setTimeout(() => FIND('box').remove(), 500);
</script>
```

### self.name

Type: `property`

The name of the component, with its version.

Example: Reading name
```html
<ui-component name="box@2"></ui-component>
<script>
    COMPONENT('box@2', self => console.log(self.name));  // box@2
</script>
```

### self.version

Type: `property`

The version from the name of the component.

The value is empty when the name has no version. The element also receives the `jc-v{version}` class.

Example: Reading version
```html
<ui-component name="box@2"></ui-component>
<script>
    COMPONENT('box@2', self => console.log(self.version));  // 2
</script>
```

### self.id

Type: `property`

The identifier of the instance.

The [`$id`](../ui-component/#x-id) configuration key sets it. Otherwise it has the same value as `ID`.

Example: Reading id
```html
<ui-component name="box" config="$id:orders"></ui-component>
<script>
    COMPONENT('box', self => self.make = () => console.log(self.id));  // orders
</script>
```

### self.ID

Type: `property`

The unique generated identifier of the instance.

Example: Reading ID
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', self => console.log(self.ID.substring(0, 2)));  // jc
</script>
```

### self.path

Type: `property`

The path of the data model bound to the instance.

The value is empty when the component has no path.

Example: Reading path
```html
<ui-component name="box" path="form.name"></ui-component>
<script>
    COMPONENT('box', self => console.log(self.path));  // form.name
</script>
```

### self.type

Type: `property`

The data type of the instance.

The value is passed to parsers and formatters. Set it in the declaration or with the [`$type`](../ui-component/#x-type) key.

Example: Reading type
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', function(self) {
        self.type = 'number';
        self.parser((path, value, type) => console.log(type));  // number
        self.make = () => self.parser('1');
    });
</script>
```

### self.format

Type: `property`

The format passed to parsers and formatters.

When the property is empty, `config.format` is used.

Example: Reading format
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', function(self) {
        self.format = 'dd.MM.yyyy';
        self.formatter((path, value, type, format) => console.log(format));  // dd.MM.yyyy
        self.make = () => self.formatter('1');
    });
</script>
```

### self.trim

Type: `property`

Removes spaces around text in the parser.

The default value is `true`.

Example: Reading trim
```html
<ui-component name="box" path="form.name"></ui-component>
<script>
    COMPONENT('box', function(self) {
        self.trim = false;
        self.make = () => console.log(self.parser('  A  ').length);  // 5
    });
</script>
```

### self.config

Type: `property`

The configuration object.

It also holds the state keys `modified`, `touched`, `invalid` and, when set, `disabled`.

Example: Reading config
```html
<ui-component name="box" config="title:Orders"></ui-component>
<script>
    COMPONENT('box', self => console.log(self.config.title, self.config.touched));  // Orders false
</script>
```

### self.element

Type: `property`

The element of the instance as a jQuery object.

Example: Reading element
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', self => console.log(self.element.prop('tagName')));  // UI-COMPONENT
</script>
```

### self.dom

Type: `property`

The element of the instance as a DOM node.

Example: Reading dom
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', self => console.log(self.dom.tagName));  // UI-COMPONENT
</script>
```

### self.owner

Type: `property`

The closest parent component.

The property is missing when the component has no parent component.

Example: Reading owner
```html
<ui-component name="parent"><ui-component name="child"></ui-component></ui-component>
<script>
    COMPONENT('parent', function(self) {});
    COMPONENT('child', self => console.log(self.owner.name));  // parent
</script>
```

### self.caller

Type: `property`

The component that called this instance through `exec()`.

Example: Reading caller
```html
<ui-component name="parent"><ui-component name="child"></ui-component></ui-component>
<script>
    COMPONENT('parent', function(self) {});
    COMPONENT('child', function(self) {
        self.ping = () => console.log(self.caller.name);  // parent
    });
    setTimeout(() => FIND('parent').exec('ping'), 500);
</script>
```

### self.global

Type: `property`

An object shared by all instances of the component.

Example: Reading global
```html
<ui-component name="box"></ui-component>
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', function(self) {
        self.global.count = (self.global.count || 0) + 1;
    });
    setTimeout(() => console.log(FIND('box').global.count), 500);  // 2
</script>
```

### self.scope

Type: `property`

The [Scope](../scope/) of the instance.

The property exists when the path contains `?`.

Example: Reading scope
```html
<ui-plugin path="users"><ui-component name="box" path="?.name"></ui-component></ui-plugin>
<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', self => console.log(self.scope.path));  // users
</script>
```

### self.pathscope

Type: `property`

The path of the scope of the instance.

The property exists when the path contains `?`.

Example: Reading pathscope
```html
<ui-plugin path="users"><ui-component name="box" path="?.name"></ui-component></ui-plugin>
<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', self => console.log(self.pathscope));  // users
</script>
```

### self.plugin

Type: `property`

The [Plugin](../plugin/) of the scope of the instance.

The property exists when the path contains `?`.

Example: Reading plugin
```html
<ui-plugin path="users"><ui-component name="box" path="?.name"></ui-component></ui-plugin>
<script>
    PLUGIN('users', function(exports) {});
    COMPONENT('box', self => console.log(self.plugin.name));  // users
</script>
```

### self.siblings

Type: `property`

Tells whether the element hosts several components.

Example: Reading siblings
```html
<ui-component name="a,b"></ui-component>
<script>
    COMPONENT('a', self => console.log(self.siblings));  // true
    COMPONENT('b', function(self) {});
</script>
```

### self.removed

Type: `property`

Tells whether the instance has been removed.

Example: Reading removed
```html
<ui-component name="box"></ui-component>
<script>
    COMPONENT('box', function(self) {});
    setTimeout(function() {
        var com = FIND('box');
        com.remove();
        console.log(com.removed);  // true
    }, 500);
</script>
```

### com.get([path])

Type: `method`

Returns the value of the bound path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Another path. |

Returns: `Object` The value.

With an argument, the method reads another path.

Example: Using get()
```js
var com = FIND('demo');
SET('form.name', 'Peter');
console.log(com.get());  // Peter
```

### com.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 passed to the setter. |

Returns: `Component` The instance.

The instance is marked as modified.

Example: Using set()
```js
var com = FIND('demo');
com.set('Peter');
console.log(GET('form.name'), com.config.modified);  // Peter true
```

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

Type: `method`

Writes a value through the parsers.

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

Returns: `Component` The instance.

The instance is marked as touched.

Example: Using modify()
```js
var com = FIND('demo');
com.modify('  Peter  ');
console.log(GET('form.name'), com.config.touched);  // Peter true
```

### com.inc(value, [type])

Type: `method`

Increases the number stored in the bound path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Number` | yes |  | The increment. |
| `type` | `Number` | no |  | The type passed to the setter. |

Returns: `Component` The instance.

Example: Using inc()
```js
var com = FIND('demo');
com.set(5);
com.inc(2);
console.log(GET('form.name'));  // 7
```

### com.extend(value, [type])

Type: `method`

Merges an object into the bound path.

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

Returns: `Component` The instance.

Example: Using extend()
```js
var com = FIND('demo');
com.set({ a: 1 });
com.extend({ b: 2 });
console.log(GET('form.name'));  // {"a":1,"b":2}
```

### com.push(value, [type])

Type: `method`

Adds an item to the array stored in the bound path.

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

Returns: `Component` The instance.

Example: Using push()
```js
var com = FIND('demo');
com.push('A');
com.push('B');
console.log(GET('form.name'));  // ["A","B"]
```

### com.rewrite(value, [type])

Type: `method`

Writes a value without notifying anyone.

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

Returns: `Component` The instance.

Bound components, binders and watchers are not called.

Example: Using rewrite()
```js
var com = FIND('demo');
com.rewrite('Peter');
console.log(GET('form.name'));  // Peter
```

### com.update([type])

Type: `method`

Writes the current value again.

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

Returns: `Component` The instance.

All listeners of the path are notified.

Example: Using update()
```js
var com = FIND('demo');
com.watch(function(path, value) {
    console.log(value);  // Peter
});
window.form.name = 'Peter';
com.update();
```

### com.refresh([notify], [type])

Type: `method`

Calls the setter of this instance with the current value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `notify` | `Boolean` | no |  | `true` notifies all listeners. |
| `type` | `Number|String` | no |  | The type passed to the setter. |

Returns: `Component` The instance.

With `notify`, the value is written to the path and all listeners are notified.

Example: Using refresh()
```js
var com = FIND('demo');
window.form.name = 'Peter';
com.refresh();
console.log(com.text());  // Peter
```

### com.notify()

Type: `method`

Notifies the listeners of the exact bound path.

Returns: `Component` The instance.

The method calls `NOTIFY()` with the path of the instance.

Example: Using notify()
```js
var com = FIND('demo');
window.form.name = 'Peter';
com.notify();
console.log(com.text());  // Peter
```

### com.skip()

Type: `method`

Skips the next call of the setter.

Returns: `Component` The instance.

Example: Using skip()
```js
var com = FIND('demo');
com.skip();
com.set('Peter');
setTimeout(() => console.log(com.text() || 'empty'), 500);  // empty
```

### com.bind(flags, [value])

Type: `method`

Changes the state and optionally writes a value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `flags` | `String` | yes |  | The flags. |
| `value` | `Object` | no |  | The value to write. |

The `flags` argument is a list of words separated by a space, a comma or `|`. An optional `@` prefix is ignored.

| Flag | Effect |
| --- | --- |
| `touched`, `touch` | Marks the instance as touched. |
| `modified`, `modify`, `changed`, `change` | Marks the instance as modified. |
| `reset` | Clears the touched and modified state. |
| `validate` | Validates the value. |
| `setter` | Calls the setter. |

When `value` is passed, it is written to the path, and the setter of this instance runs only with the `setter` flag.

Example: Using bind()
```js
var com = FIND('demo');
com.bind('@touched @modified', 'Peter');
console.log(GET('form.name'), com.config.touched, com.config.modified);  // Peter true true
```

### com.reset()

Type: `method`

Clears the touched and modified state.

Returns: `Component` The instance.

The value is validated again.

Example: Using reset()
```js
var com = FIND('demo');
com.modify('Peter');
com.reset();
console.log(com.config.touched, com.config.modified);  // false false
```

### com.default([reset])

Type: `method`

Restores the default value of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `reset` | `Boolean` | no | `true` | `false` keeps the state of the instance. |

Returns: `Component` The instance.

The default value comes from the [`default`](../ui-component/#default) attribute.

Example: Using default()
```js
var com = FIND('demo');
com.set('Peter');
com.default();
console.log(GET('form.name'));  // Anonymous
```

### com.change([value])

Type: `method`

Sets the touched and modified state of components on the path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Boolean` | no | `true` | The new state. |

Returns: `Component` The instance.

The method applies to all components bound to the path and its nested paths. The method is also available as `touched()`.

Example: Using change()
```js
var com = FIND('demo');
com.change();
console.log(com.config.touched, com.config.modified);  // true true
```

### com.dirty([value], [noemit])

Type: `method`

Reads or sets the untouched state.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Boolean` | no |  | `false` marks the instance as touched. |
| `noemit` | `Boolean` | no |  | `true` skips the `state` delegate. |

Returns: `Boolean|Component` The state, or the instance when `value` is passed.

Without arguments, the method returns `true` for an untouched instance.

Example: Using dirty()
```js
var com = FIND('demo');
console.log(com.dirty());  // true
com.dirty(false);
console.log(com.config.touched);  // true
```

### com.isInvalid()

Type: `method`

Tells whether the instance is touched and invalid.

Returns: `Boolean` The result.

Example: Using isInvalid()
```js
var com = FIND('demo');
com.validate = value => !!value;
com.modify('');
com.validate2();
com.bind('touched');
console.log(com.isInvalid());  // true
```

### com.validate2()

Type: `method`

Runs the `validate` delegate and updates the state.

Returns: `Boolean` `true` for a valid value.

Example: Using validate2()
```js
var com = FIND('demo');
com.validate = value => !!value;
console.log(com.validate2());  // false
```

### com.notmodified([fields])

Type: `method`

Tells whether the value is the same as at the last check.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fields` | `String|Array` | no |  | The fields to compare. |

Returns: `Boolean` `true` when the value has not changed.

The first check returns `false`.

Example: Using notmodified()
```js
var com = FIND('demo');
com.set('Peter');
console.log(com.notmodified());  // false
console.log(com.notmodified());  // true
```

### com.parser(value, [prepend])

Type: `method`

Adds a parser, or parses a value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Function|Object` | yes |  | A parser or the value to parse. |
| `prepend` | `Boolean` | no |  | `true` adds the parser to the beginning. |

Returns: `Object` The parsed value, or the instance when a parser is added.

A function is added to the parsers of the instance. It receives `path`, `value`, `type` and `format`, and returns the new value. Any other argument is parsed and returned.

Example: Using parser()
```js
var com = FIND('demo');
com.parser((path, value) => value.toUpperCase());
console.log(com.parser('peter'));  // PETER
```

### com.formatter(value, [prepend])

Type: `method`

Adds a formatter, or formats a value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Function|Object` | yes |  | A formatter or the value to format. |
| `prepend` | `Boolean` | no |  | `true` adds the formatter to the beginning. |

Returns: `Object` The formatted value, or the instance when a formatter is added.

A function is added to the formatters of the instance. It receives `path`, `value`, `type` and `format`, and returns the new value. Any other argument is formatted and returned.

Example: Using formatter()
```js
var com = FIND('demo');
com.formatter((path, value) => value + '!');
console.log(com.formatter('Peter'));  // Peter!
```

### com.parsesource(value)

Type: `method`

Converts a text list to an array of items.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | The list. |

Returns: `Array` Objects with `id`, `name` and `icon`.

Items are separated by a comma. Each item has the form `id|name|icon`. When the instance has the `number` type, the identifiers are converted to numbers.

Example: Using parsesource()
```js
var com = FIND('demo');
console.log(com.parsesource('1|One,2|Two|home')[1]);  // {"id":"2","name":"Two","icon":"home"}
```

### com.reconfigure(value, [callback], [init], [noemit])

Type: `method`

Changes the configuration.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Object` | yes |  | The configuration. |
| `callback` | `Function` | no |  | Receives `key`, `value`, `init` and `prev` instead of the `configure` delegate. |
| `init` | `Boolean` | no |  | The `init` argument of the delegate. |
| `noemit` | `Boolean` | no |  | `true` skips the delegate. |

Returns: `Component` The instance.

The value can be a string of `key:value` pairs, an object, or `=path` to read an object from a path. The `configure` delegate receives each key.

Example: Using reconfigure()
```js
var com = FIND('demo');
com.reconfigure('title:Orders;limit:10');
console.log(com.config.title, com.config.limit);  // Orders 10
```

### com.configdisplay(key, value)

Type: `method`

Resolves a value that depends on the display.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | The name of the key. |
| `value` | `Object` | yes |  | The value. |

Returns: `Object` The resolved value.

The value has the form `@xs=1,@md=2`. Other values are returned unchanged. See [Responsive configuration](../ui-component/#responsive-configuration).

Example: Using configdisplay()
```js
var com = FIND('demo');
console.log(com.configdisplay('size', '@xs=1,@lg=4'), WIDTH());  // 1 xs
```

### com.data(key, [value])

Type: `method`

Reads or writes data of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | The name of the key. |
| `value` | `Object` | no |  | The value to write. |

Returns: `Object` The value.

Nested elements read the keys with the `@key` path. An empty key is the current value of the instance.

Example: Using data()
```js
var com = FIND('demo');
com.data('title', 'Orders');
console.log(com.data('title'));  // Orders
```

### com.datasource(path, callback, [init])

Type: `method`

Watches a path that holds a data source.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path of the data source. |
| `callback` | `Function` | yes |  | The function that receives the data. |
| `init` | `Boolean` | no | `true` | `false` skips the initial call. |

Returns: `Component` The instance.

The callback receives `path`, `value` and `type`. Unless `init` is `false`, it also runs after the configuration is loaded. A new call replaces the previous data source.

Example: Using datasource()
```js
var com = FIND('demo');
com.datasource('common.items', function(path, value) {
    console.log(value);  // [1,2]
}, false);
SET('common.items', [1, 2]);
```

### com.watch([path], callback, [init])

Type: `method`

Watches a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | The path to watch. |
| `callback` | `Function` | yes |  | The function that receives the changes. |
| `init` | `Boolean` | no |  | `true` calls the callback immediately. |

Returns: `Component` The instance.

The callback receives `path`, `value` and `type`, and `this` is the instance. Without a path, the method watches the path of the instance. The watcher is removed together with the instance.

Example: Using watch()
```js
var com = FIND('demo');
com.watch('form.age', function(path, value) {
    console.log(path, value);  // form.age 30
});
SET('form.age', 30);
```

### com.unwatch(path)

Type: `method`

Removes the watchers of a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The watched path. |

Returns: `Component` The instance.

The method removes all watchers that this instance has on the path.

Example: Using unwatch()
```js
var com = FIND('demo');
com.watch('form.age', () => console.log('called'));
com.unwatch('form.age');
SET('form.age', 30);
console.log('end');  // end
```

### com.on(name, callback)

Type: `method`

Listens for a global event.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `callback` | `Function` | yes |  | The listener. |

Returns: `Component` The instance.

The listener is removed together with the instance. A `^` prefix of the name puts the listener first.

Example: Using on()
```js
var com = FIND('demo');
com.on('saved', value => console.log(value));  // 5
EMIT('saved', 5);
```

### com.off(name, [callback])

Type: `method`

Removes a listener of a global event.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `callback` | `Function` | no |  | The listener. |

Returns: `Component` The instance.

Without a callback, all listeners of the event in this instance are removed.

Example: Using off()
```js
var com = FIND('demo');
var fn = () => console.log('called');
com.on('saved', fn);
com.off('saved', fn);
console.log(EMIT('saved'));  // false
```

### com.emit(name, [...args])

Type: `method`

Emits a global event.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `args` | `Object` | no |  | The arguments of the event. |

Returns: `Component` The instance.

The method calls `EMIT()`.

Example: Using emit()
```js
var com = FIND('demo');
ON('saved', value => console.log(value));  // 5
com.emit('saved', 5);
```

### com.command(name, callback)

Type: `method`

Registers a command of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the command. |
| `callback` | `Function` | yes |  | The handler. |

Returns: `Component` The instance.

A `^` prefix of the name puts the handler first. Commands are called by [`CMD()`](#cmd) or by the global `CMD()`.

Example: Using command()
```js
var com = FIND('demo');
com.command('clear', () => console.log('cleared'));  // cleared
CMD('clear');
```

### com.CMD(name, [a], [b], [c], [d], [e])

Type: `method`

Calls a command of this instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the command. |

Returns: `Component` The instance.

The method accepts up to five arguments.

Example: Using CMD()
```js
var com = FIND('demo');
com.command('add', (a, b) => console.log(a + b));  // 3
com.CMD('add', 1, 2);
```

### com.exec(name, [a], [b], [c], [d], [e])

Type: `method`

Calls a method of all nested components.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the method. |

Returns: `Component` The instance.

Each nested component receives this instance in `caller`.

Example: Using exec()
```js
var com = FIND('demo');
com.exec('ping', 5);
```

### com.GET(path)

Type: `method`

Reads a path relative to the scope of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |

Returns: `Object` The value.

The `?` character is replaced with the path of the scope.

Example: Using GET()
```js
var com = FIND('demo');
SET('users.name', 'Peter');
console.log(com.GET('?.name'));  // Peter
```

### com.SET(path, value)

Type: `method`

Writes a path relative to the scope of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |
| `value` | `Object` | yes |  | The value. |

The `?` character is replaced with the path of the scope.

Example: Using SET()
```js
var com = FIND('demo');
com.SET('?.age', 30);
console.log(GET('users.age'));  // 30
```

### com.EXEC(path, [a], [b], [c], [d])

Type: `method`

Calls a function by its path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path of the function. |

Returns: `Component` The instance.

The `?` character is replaced with the path of the scope. A path with the `@` prefix calls a method of the parent component.

Example: Using EXEC()
```js
var com = FIND('child');
com.EXEC('@ping', 5);
```

### com.SEEX(path, [a], [b], [c], [d])

Type: `method`

Calls a function or writes a value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |

Returns: `Component` The instance.

The method calls the function on the path. When the path holds no function, the first argument is written to it. The `@` prefix works with the parent component.

Example: Using SEEX()
```js
var com = FIND('child');
com.SEEX('@title', 'Orders');
console.log(FIND('demo').title);  // Orders
```

### com.makepath(path)

Type: `method`

Resolves a path in the scope of the instance.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |

Returns: `String` The resolved path.

Example: Using makepath()
```js
var com = FIND('demo');
console.log(com.makepath('?.age'));  // users.age
```

### com.scopepath(path)

Type: `method`

Replaces `?` in a path with the path of the scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |

Returns: `String` The resolved path.

A path without `?` is returned unchanged.

Example: Using scopepath()
```js
var com = FIND('demo');
console.log(com.scopepath('?.age'), com.scopepath('form.age'));  // users.age form.age
```

### com.setPath(path)

Type: `method`

Changes the bound path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The new path. |

Returns: `Component` The instance.

Example: Using setPath()
```js
var com = FIND('demo');
com.setPath('form.other');
SET('form.other', 5);
console.log(com.path, com.get());  // form.other 5
```

### com.blind()

Type: `method`

Disconnects the instance from its path.

Returns: `Component` The instance.

Example: Using blind()
```js
var com = FIND('demo');
com.blind();
SET('form.name', 'Peter');
console.log(com.path, com.text() || 'empty');  // null empty
```

### self.readonly()

Type: `method`

Removes the `setter`, `getter` and `validate` delegates.

Returns: `Component` The instance.

Use it in components that only display content.

Example: Using readonly()
```js
var com = FIND('demo');
console.log(com.setter, com.getter);  // null null
```

### self.singleton()

Type: `method`

Allows only one instance of the component in the page.

Returns: `Component` The instance.

Other elements of the same component are removed.

Example: Using singleton()
```js
console.log(FIND('demo', true).length, $('ui-component').length);  // 1 1
```

### self.bindchanges([enable])

Type: `method`

Skips the setter when the value has not changed.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enable` | `Boolean` | no | `true` | `false` turns the feature off. |

Returns: `Component` The instance.

Example: Using bindchanges()
```js
SET('form.name', 'A');
SET('form.name', 'A');
setTimeout(() => console.log(window.calls), 500);  // 2
```

### self.bindexact([enable])

Type: `method`

Ignores changes of nested paths.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enable` | `Boolean` | no | `true` | `false` turns the feature off. |

Returns: `Component` The instance.

The setter runs only for the exact path or its parents.

Example: Using bindexact()
```js
SET('form.user.name', 'Peter');
setTimeout(() => console.log(window.calls), 500);  // 1
```

### self.bindvisible([timeout])

Type: `method`

Delays the setter until the element is visible.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `timeout` | `Number|Boolean` | no | `DEF.delaybinder` | The delay in milliseconds after the element becomes visible. `false` turns the feature off. |

Returns: `Component` The instance.

Example: Using bindvisible()
```js
SET('form.name', 'Peter');
setTimeout(() => $('#tab').show(), 500);
setTimeout(() => console.log($('ui-component').text()), 1500);  // Peter
```

### self.autofill([enable])

Type: `method`

Reads values filled in by the browser.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enable` | `Boolean` | no | `true` | `false` turns the feature off. |

Returns: `Component` The instance.

After the page is ready, the value of nested fields with the `data-jc-bind` attribute is written to the path.

Example: Using autofill()
```js
$('input').val('Peter');
setTimeout(() => console.log(GET('form.name')), 1400);  // Peter
```

### com.caniuse(name)

Type: `method`

Tells whether a component is available.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the component. |

Returns: `Number` `1` for a declared component, `2` for a lazy one, `undefined` for an unknown one.

Example: Using caniuse()
```js
var com = FIND('demo');
console.log(com.caniuse('demo'));  // 1
```

### com.main()

Type: `method`

Returns the closest parent component.

Returns: `Component` The parent component or `null`.

Example: Using main()
```js
var com = FIND('child');
console.log(com.main().name);  // demo
```

### com.compile([container])

Type: `method`

Compiles new content of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `container` | `jQuery|Element` | no | `the component element` | The element to compile. |

Returns: `Component` The instance.

Call it after you add elements with bindings or components.

Example: Using compile()
```js
var com = FIND('demo');
com.append('<div data-bind="form.name__text"></div>');
com.compile();
SET('form.name', 'Peter');
setTimeout(() => console.log(com.find('div').text()), 500);  // Peter
```

### com.import(url, [callback], [insert], [preparator])

Type: `method`

Imports content into the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | The URL. |
| `callback` | `Function` | no |  | Runs after the import. |
| `insert` | `Boolean` | no |  | The `insert` argument of `IMPORT()`. |
| `preparator` | `Function` | no |  | Changes the response before the insertion. |

Returns: `Component` The instance.

The method calls `IMPORT()` with the element as the target.

Example: Using import()
```js
var com = FIND('demo');
com.import('/part.html', () => console.log('imported'));  // imported
```

### com.replace(element, [remove])

Type: `method`

Moves the instance to another element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery|Element` | yes |  | The new element. |
| `remove` | `Boolean` | no |  | `true` removes the original element. |

Returns: `Component` The instance.

Example: Using replace()
```js
var com = FIND('demo');
com.replace($('#target'), true);
console.log(com.dom.id, $('ui-component').length);  // target 0
```

### com.remove([noclear])

Type: `method`

Removes the instance and its element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `noclear` | `Boolean` | no |  | `true` does not start the cleanup immediately. |

Returns: `Boolean` Always `true`.

The `destroy` delegate runs during the cleanup. The method is also available as `kill()`.

Example: Using remove()
```js
var com = FIND('demo');
console.log(com.remove());  // true
```

### com.find(selector)

Type: `method`

Finds nested elements.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String|Object` | yes |  | A selector or an object of selectors. |

Returns: `jQuery|Object` The result.

An object of selectors returns an object of jQuery results with the same keys.

Example: Using find()
```js
var com = FIND('demo');
console.log(com.find('.label').text());  // Text
```

### com.closest(selector)

Type: `method`

Finds the closest matching parent.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | The selector. |

Returns: `jQuery` The result.

Example: Using closest()
```js
var com = FIND('demo');
console.log(com.closest('body').length);  // 1
```

### com.parent([selector])

Type: `method`

Returns a parent element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no |  | The selector. |

Returns: `jQuery` The result.

The argument can be:

| Value | Result |
| --- | --- |
| omitted | The direct parent. |
| A selector | The closest matching element. |
| `auto` | The closest parent with a defined height, otherwise `window`. |
| `window` | `window` as a jQuery object. |
| `document` | The `document` object. |
| `parent` | The direct parent. |
| `parent2` | The element two levels above the direct parent. |

Example: Using parent()
```js
var com = FIND('demo');
console.log(com.parent().prop('tagName'));  // BODY
```

### com.html([value])

Type: `method`

Reads or replaces the HTML content.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | no |  | The new content. |

Returns: `String|jQuery` The content, or the element when `value` is passed.

An array is joined.

Example: Using html()
```js
var com = FIND('demo');
com.html('<b>A</b>');
console.log(com.html());  // <b>A</b>
```

### com.text([value])

Type: `method`

Reads or replaces the text content.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | no |  | The new content. |

Returns: `String|jQuery` The content, or the element when `value` is passed.

An array is joined.

Example: Using text()
```js
var com = FIND('demo');
com.text('<b>A</b>');
console.log(com.html());  // &lt;b&gt;A&lt;/b&gt;
```

### com.append(value)

Type: `method`

Adds content to the end of the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | yes |  | The content. |

Returns: `jQuery` The element.

An array is joined.

Example: Using append()
```js
var com = FIND('demo');
com.empty();
com.append('<b>A</b>');
console.log(com.html());  // <b>A</b>
```

### com.empty()

Type: `method`

Removes the content of the element.

Returns: `jQuery` The element.

Nested components are removed too.

Example: Using empty()
```js
var com = FIND('demo');
com.empty();
console.log(com.html() === '');  // true
```

### com.event(name, [selector], callback)

Type: `method`

Attaches a jQuery event to the element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `selector` | `String` | no |  | The delegated selector. |
| `callback` | `Function` | yes |  | The handler. |

Returns: `Component` The instance.

The arguments are the same as in the jQuery `on()` method.

Example: Using event()
```js
var com = FIND('demo');
com.event('click', '.label', () => console.log('clicked'));  // clicked
com.find('.label').click();
```

### com.aclass(classes, [timeout])

Type: `method`

Adds CSS classes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | yes |  | The classes. |
| `timeout` | `Number` | no |  | The delay in milliseconds. |

Returns: `Component` The instance.

Example: Using aclass()
```js
var com = FIND('demo');
com.aclass('active');
console.log(com.hclass('active'));  // true
```

### com.rclass([classes], [timeout])

Type: `method`

Removes CSS classes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | no |  | The classes. |
| `timeout` | `Number` | no |  | The delay in milliseconds. |

Returns: `Component` The instance.

Without an argument, all classes are removed.

Example: Using rclass()
```js
var com = FIND('demo');
com.aclass('active');
com.rclass('active');
console.log(com.hclass('active'));  // false
```

### com.rclass2(search)

Type: `method`

Removes CSS classes that contain a text.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String|RegExp` | yes |  | The text or a regular expression. |

Returns: `Component` The instance.

Example: Using rclass2()
```js
var com = FIND('demo');
com.aclass('col-1 col-2');
com.rclass2('col-');
console.log(com.hclass('col-1'));  // false
```

### com.tclass(classes, [state])

Type: `method`

Toggles CSS classes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | yes |  | The classes. |
| `state` | `Boolean` | no |  | Forces the state. |

Returns: `Component` The instance.

Example: Using tclass()
```js
var com = FIND('demo');
com.tclass('active', true);
console.log(com.hclass('active'));  // true
```

### com.hclass(name)

Type: `method`

Tells whether the element has a CSS class.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The class. |

Returns: `Boolean` The result.

Example: Using hclass()
```js
var com = FIND('demo');
console.log(com.hclass('missing'));  // false
```

### com.attr(name, [value])

Type: `method`

Reads or writes an attribute.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The attribute. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Component` The value, or the instance when `value` is passed.

Example: Using attr()
```js
var com = FIND('demo');
com.attr('title', 'Orders');
console.log(com.attr('title'));  // Orders
```

### com.attrd(name, [value])

Type: `method`

Reads or writes a `data-` attribute.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name without the `data-` prefix. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Component` The value, or the instance when `value` is passed.

Example: Using attrd()
```js
var com = FIND('demo');
com.attrd('id', '5');
console.log(com.attr('data-id'));  // 5
```

### com.attrd2(name)

Type: `method`

Reads a `data-` attribute from the element or its closest parent that has it.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name without the `data-` prefix. |

Returns: `String` The value.

Example: Using attrd2()
```js
var com = FIND('demo');
console.log(com.attrd2('group'));  // main
```

### com.css(name, [value])

Type: `method`

Reads or writes a CSS property.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The property. |
| `value` | `String` | no |  | The new value. |

Returns: `String|Component` The value, or the instance when `value` is passed.

Example: Using css()
```js
var com = FIND('demo');
com.css('display', 'block');
console.log(com.css('display'));  // block
```

### com.visible([callback])

Type: `method`

Tells whether the element is visible.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Runs when the element is visible. |

Returns: `Boolean` The current visibility.

With a callback, the function runs as soon as the element is visible.

Example: Using visible()
```js
var com = FIND('demo');
console.log(com.visible());  // true
```

### com.width([callback])

Type: `method`

Returns the width of the element in pixels.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Receives the width. |

Returns: `Number` The width.

With a callback, the function runs as soon as the width is greater than zero.

Example: Using width()
```js
var com = FIND('demo');
com.css('display', 'block');
com.css('width', '200px');
console.log(com.width());  // 200
```

### com.height([callback])

Type: `method`

Returns the height of the element in pixels.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Receives the height. |

Returns: `Number` The height.

With a callback, the function runs as soon as the height is greater than zero.

Example: Using height()
```js
var com = FIND('demo');
com.css('display', 'block');
com.css('height', '50px');
console.log(com.height());  // 50
```

### com.autofocus([selector])

Type: `method`

Moves the focus to the first visible field.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `input,select,textarea` | The fields. |

Returns: `Component` The instance.

The method tries again for a short time when no field can receive the focus. It does nothing on mobile devices.

Example: Using autofocus()
```js
var com = FIND('demo');
com.autofocus();
console.log(document.activeElement.tagName);  // INPUT
```

### com.faicon(value)

Type: `method`

Completes the name of an icon.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | The name of the icon. |

Returns: `String` The CSS classes.

A name without a space receives `DEF.iconprefix`, which is `ti ti-`. The method is also available as `icon()`.

Example: Using faicon()
```js
var com = FIND('demo');
console.log(com.faicon('home'));  // ti ti-home
```
