---
title: "Riferimento dell'istanza"
project: Total.js UI Builder
version: 1.0
section: development
language: it
license: MIT
url: https://totaljs.es/docs/it/uibuilder/1-0/development/instance-api/
updated: 2026-11-20T06:51:57.969Z
---

# Riferimento dell'istanza

> Le proprietà, i metodi e gli eventi dell'oggetto istanza che exports.make riceve.

L'istanza è una copia del componente in un design. `exports.make` la riceve come primo argomento:

```js
exports.make = function(instance, config, element) {

	instance.on('value', function(value) {
		element.text(value);
	});

};
```

Le voci di tipo **event** sono nomi per `instance.on()`. Le voci di tipo **method** sono funzioni dell'istanza; le voci **property** sono i suoi dati. Alcuni eventi avvengono solo nell'editor, come indicano le loro voci.

## API

### instance.id

Type: `property`

L'id dell'istanza nel design, per esempio `cid6wh0tx52`.

### instance.config

Type: `property`

La configurazione dell'istanza.

### instance.element

Type: `property`

L'elemento dell'istanza, un oggetto jQuery.

Ha le classi `UI_component`, `ui_` più l'id del componente, e la classe del componente.

### instance.dom

Type: `property`

L'elemento dell'istanza, come elemento DOM.

### instance.component

Type: `property`

La dichiarazione del componente: `exports` con `id`, `name`, `html`, `readme` e le altre proprietà.

### instance.app

Type: `property`

L'app del design. Leggi [Riferimento dell'app](../app-api/).

### instance.parent

Type: `property`

L'istanza che contiene questa.

### instance.children

Type: `property`

Le istanze direttamente all'interno di questa.

### instance.args

Type: `property`

I **Dynamic arguments** (argomenti dinamici) del design.

### instance.state

Type: `property`

Lo stato dell'istanza: `value`, `modified`, `touched`, `invalid`, `disabled` e `readonly`, e i flag `bind`, `notify` e `validate`.

Imposta `instance.state.bind = true` per permettere a un **Form** di leggere e scrivere il valore. Imposta `instance.state.notify = true` per ricevere `notify` invece dei nuovi valori dall'istanza che segui. Imposta `instance.state.validate = false` per disattivare `instance.check()`. Leggi [Valori e data binding](../values-and-binding/).

### instance.cache

Type: `property`

Un oggetto per i tuoi dati temporanei.

### instance.outputs = [{ id, name }]

Type: `property`

Uscite solo di questa istanza, al posto di `exports.outputs`.

`instance.inputs` fa lo stesso per l'elenco degli ingressi nell'editor.

### instance.validate = function() {}

Type: `delegate`

Controlla il valore. Definiscila nel tuo codice.

Returns: `Boolean` `true` quando il valore è valido.

Restituisci `true` quando il valore è valido, e `false` o un testo di errore quando non lo è. `instance.check()` la chiama.

Example: Un numero obbligatorio
```js
instance.validate = function() {
	var value = instance.get();
	return value != null && value >= config.min && value <= config.max;
};
```

### instance.default = function() {}

Type: `delegate`

Restituisce il valore predefinito. Definiscila nel tuo codice.

Returns: `Object` Il valore predefinito.

Un **Form** lo imposta quando svuota i suoi componenti.

### instance.set(type, value, [kind])

Type: `method`

Imposta il valore o un'altra parte dello stato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | `value`, `modified`, `touched`, `invalid`, `disabled` o `readonly`. |
| `value` | `Object` | yes |  | Il nuovo valore. |
| `kind` | `String` | no |  | Una parola a tua scelta, passata agli eventi `set` e `value`. `force` imposta il valore anche quando è uguale a quello attuale; `noemitstate` non annuncia la modifica ai genitori. |

Returns: `Boolean` `false` quando non è cambiato niente.

Impostare `value` emette `value`, passa il valore alle istanze che seguono questa ed esegue `instance.check()`. Impostare `modified`, `touched`, `invalid`, `disabled` o `readonly` attiva o disattiva la classe corrispondente sull'elemento, per esempio `UI_touched`. La modifica viene annunciata alle istanze genitore come `state`.

Example: Impostare il valore dopo un clic
```js
instance.set('value', value);
instance.set('modified', true);
instance.set('touched', true);
```

### instance.get([type])

Type: `method`

Restituisce il valore o un'altra parte dello stato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no | `value` | Una chiave dello stato. |

Returns: `Object` Il valore.

### instance.on(name, fn)

Type: `method`

Registra un gestore di eventi.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `fn` | `Function` | yes |  | Il gestore. |

Puoi unire più nomi con uno spazio o con `+`.

### instance.off(name, [fn])

Type: `method`

Rimuove un gestore di eventi, o tutti i gestori dell'evento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `fn` | `Function` | no |  | Il gestore da rimuovere. |

### instance.emit(name, [a], [b], [c], [d], [e])

Type: `method`

Chiama i gestori di un evento di questa istanza.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `a` | `Object` | no |  | Argomenti per i gestori, fino a cinque. |

Example: Disegnare l'aspetto iniziale
```js
instance.emit('configure');
```

### instance.input(id, fn)

Type: `method`

Gestisce un ingresso del componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'id dell'ingresso in `exports.inputs`. |
| `fn` | `Function` | yes |  | Riceve `(data, callback)`. |

Leggi [Ingressi e uscite](../inputs-outputs/).

### instance.output(id, [data])

Type: `method`

Invia un'uscita, o registra la funzione che ne produce i dati.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'id dell'uscita. |
| `data` | `Object` | no |  | I dati, o una funzione che riceve `next`. |

Con dei dati, li invia subito. Con una funzione, la registra; una chiamata successiva senza dati la esegue con `next(err, data)`. L'uscita deve essere dichiarata.

Example: Inviare un valore
```js
instance.output('change', value);
```

### instance.check([force])

Type: `method`

Esegue `instance.validate` e imposta `invalid`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `force` | `Boolean` | no | `false` | Controllare subito. |

Viene eseguito dopo 50 ms, o subito con `force`. Un'istanza disattivata o in sola lettura è sempre valida.

### instance.errors()

Type: `method`

Restituisce gli errori di un'istanza non valida.

Returns: `Array` Un elenco di `{ error: String }`.

Quando `invalid` contiene un testo o un elenco di testi, vengono restituiti come oggetti.

### instance.reset()

Type: `method`

Emette `reset` sull'istanza.

### instance.reconfigure(config)

Type: `method`

Cambia delle chiavi della configurazione ed emette `configure` con i valori precedenti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `config` | `Object` | yes |  | Le chiavi da cambiare. |

### instance.find(id)

Type: `method`

Trova un'altra istanza del design.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'id, `@` e l'id, oppure `.` e un percorso. |

Returns: `Object` L'istanza, o `undefined`.

### instance.readvalue([id])

Type: `method`

Restituisce il valore di questa istanza o di un'altra.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | no |  | L'id di un'altra istanza. |

Returns: `Object` Il valore.

### instance.watch(id, fn)

Type: `method`

Esegue `fn` ogni volta che il valore di un'altra istanza cambia.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'id dell'istanza. |
| `fn` | `Function` | yes |  | Riceve il valore. |

### instance.datasource(id, fn)

Type: `method`

Legge un elenco di elementi da una sorgente di dati e chiama `fn` con una copia.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | La sorgente di dati, di solito il valore di un campo con `dirsource:#datasource`. |
| `fn` | `Function` | yes |  | Riceve l'array. |

Con `@` e l'id di un'istanza, legge il suo valore e chiama di nuovo `fn` quando il valore cambia. Il valore deve essere un array, o un oggetto con `items`. Gli elenchi di codici e le viste di dati arrivano dall'app che mostra il design.

### instance.family([index])

Type: `method`

Restituisce tutte le istanze all'interno di questa, a ogni livello.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `index` | `Number` | no |  | Solo le istanze nell'area con questo `data-index`. |

Returns: `Array` Le istanze.

### instance.hidden()

Type: `method`

Dice se l'elemento è nascosto.

Returns: `Boolean` `true` quando è nascosto.

### instance.read(obj, path)

Type: `method`

Legge un valore da un oggetto tramite un percorso con punti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | L'oggetto. |
| `path` | `String` | yes |  | Per esempio `address.city`. |

Returns: `Object` Il valore.

Example: Leggere una chiave annidata
```js
instance.read({ a: { b: 5 } }, 'a.b'); // 5
```

### instance.write(obj, path, value)

Type: `method`

Scrive un valore in un oggetto tramite un percorso con punti, e crea gli oggetti lungo il percorso.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | L'oggetto. |
| `path` | `String` | yes |  | Per esempio `address.city`. |
| `value` | `Object` | yes |  | Il valore. |

Returns: `Object` L'oggetto che contiene l'ultima chiave.

### instance.maketemplate([html])

Type: `method`

Compila un template Tangular e lo tiene in una cache.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `html` | `String` | no |  | Il template. |

Returns: `Function` Una funzione che restituisce l'HTML per un modello.

Senza `html`, usa il `<body>` del componente.

Example: Mostrare un'etichetta
```js
var label = instance.maketemplate('<label>{{ name }}:</label>');
element.html(label(config));
```

### instance.replace(text, [data], [encoder])

Type: `method`

Riempie `{args.key}`, `{config.key}`, `{user.key}` e `{data.key}` in un testo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | yes |  | Il testo. |
| `data` | `Object` | no |  | I dati per `{data.key}`. |
| `encoder` | `String` | no |  | `url`, `html` o `json` per codificare i valori, oppure una funzione. |

Returns: `String` Il testo.

`args` sono i **Dynamic arguments**, `config` la configurazione, `user` l'oggetto `window.user` della pagina e `data` il secondo argomento.

Example: Usare un argomento dinamico
```js
instance.replace('Hi {args.who}'); // 'Hi Jane' when the argument who is Jane
```

### instance.wait(fn, callback)

Type: `method`

Chiama `callback` quando `fn` restituisce un valore vero, controllando ogni 300 ms.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | yes |  | Il controllo. |
| `callback` | `Function` | yes |  | Viene eseguita una volta. |

### instance.error(err)

Type: `method`

Scrive un errore nella console con i nomi del componente e dell'istanza.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `err` | `Object` | yes |  | L'errore. |

### instance.edit(el, [options])

Type: `method`

Rende un elemento modificabile nell'area di lavoro. Solo nell'editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `el` | `Element` | yes |  | L'elemento. |
| `options` | `Object` | no |  | Per esempio `{ multiline: true }`. |

Leggi [Modificare il testo nell'area di lavoro](../canvas-editing/).

### instance.remove()

Type: `method`

Rimuove l'istanza dal design.

### instance.on('configure', function(changes) {})

Type: `event`

La configurazione è cambiata. Editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `changes` | `Object` | yes |  | I valori precedenti. |

Viene emesso dopo che l'utente invia il modulo delle impostazioni e dopo `instance.reconfigure()`. `changes` contiene i valori precedenti delle chiavi cambiate.

### instance.on('ready', function() {})

Type: `event`

Tutte le istanze del design sono state costruite.

Viene emesso una volta quando il design è costruito. Un'istanza che l'utente rilascia più tardi nell'area di lavoro non lo riceve.

### instance.on('value', function(value, kind) {})

Type: `event`

Il valore è cambiato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Il nuovo valore. |
| `kind` | `String` | no |  | Il `kind` passato a `instance.set()`. |

### instance.on('set', function(type, value, kind) {})

Type: `event`

Una parte dello stato è cambiata.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | La chiave dello stato, per esempio `value` o `touched`. |
| `value` | `Object` | yes |  | Il nuovo valore. |
| `kind` | `String` | no |  | Il `kind` passato a `instance.set()`. |

### instance.on('notify', function(value, from) {})

Type: `event`

L'istanza che segui ha un nuovo valore, con `instance.state.notify` attivo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Una copia del valore. |
| `from` | `Object` | yes |  | L'istanza che ha il valore. |

### instance.on('state', function(e) {})

Type: `event`

Lo stato di un'istanza all'interno di questa è cambiato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `e` | `Object` | yes |  | L'evento. |

`e.instance` è quell'istanza, `e.changes` le chiavi cambiate, per esempio `{ value: 1 }`, ed `e.state` il suo stato. `e.stopPropagation()` ferma l'evento a questa istanza. Le altre istanze ricevono lo stesso evento come `@state`.

### instance.on('reset', function() {})

Type: `event`

Un **Form** o `instance.reset()` reimposta l'istanza.

Qui azzera `touched` e `modified`.

### instance.on('resize', function(meta) {})

Type: `event`

La finestra ha cambiato dimensione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `meta` | `Object` | yes |  | La dimensione. |

`meta.width` e `meta.height` sono la dimensione del design, `meta.display` la dimensione dello schermo: `xs`, `sm`, `md` o `lg`.

### instance.on('service', function(counter) {})

Type: `event`

Viene emesso ogni minuto mentre il design è sulla pagina.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Quante volte è stato emesso. |

### instance.on('destroy', function() {})

Type: `event`

L'istanza viene rimossa. Qui ferma i timer.

### instance.on('settings', function(config) {})

Type: `event`

Il modulo delle impostazioni sta per aprirsi. Editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `config` | `Object` | yes |  | La copia. |

`config` è la copia della configurazione che il modulo modifica.

### instance.on('stringify', function(meta, isbuild) {})

Type: `event`

Il design viene salvato o pubblicato. Editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `meta` | `Object` | yes |  | I dati dell'istanza. |
| `isbuild` | `Boolean` | yes |  | `true` durante la pubblicazione. |

`meta` sono i dati salvati dell'istanza; cambia `meta.config` per cambiare ciò che viene salvato. `isbuild` è `true` quando il design viene pubblicato.

### instance.on('refresh', function(meta) {})

Type: `event`

Qualcosa nel design è cambiato. Editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `meta` | `Object` | yes |  | Cosa è cambiato. |

`meta.type` è `configure` (un'altra istanza ha cambiato le sue impostazioni, in `meta.item`), `remove` (sono state rimosse delle istanze, in `meta.items`), `paths` o `apps`.

### instance.on('html', function(el) {})

Type: `event`

L'utente ha modificato nell'area di lavoro un testo, un'icona o un link dell'istanza. Editor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `el` | `jQuery` | yes |  | L'elemento modificato. |

Leggi [Modificare il testo nell'area di lavoro](../canvas-editing/).
