# wires

Source: https://zotonic.com/docs/3096/wires

URI: https://zotonic.com/id/3096

Language: en



Resolve JavaScript dependencies for automatic widget loading in <a href="/id/doc_module_mod_wires" class="doc-reference doc-reference-module"><code>module#mod_wires</code></a>. The widget manager uses this model when a `do_<name>` class has no registered jQuery function yet.

Available Model API Paths
-------------------------

| Method | Path pattern    | Description                                                                      |
| ------ | --------------- | -------------------------------------------------------------------------------- |
| `get`  | `/widget/+name` | Resolve `js/modules/z.<name>.js` and return a list containing its asset descriptor. |

`+name` is a single widget name containing letters, digits, underscores or hyphens, without the `do_` prefix. Resolution uses the site's library index, including enabled modules. The descriptor contains `key`, a timestamped `url`, `type`, `media`, `rel` and `title`, as returned by `z_lib_include:assets/3`. The request payload is ignored. The model resolves the asset; it does not load it or initialize the widget.

For example, load the library for `do_autofocus` in the browser:

```javascript
cotonic.ready.then(() => cotonic.broker.call(
    'bridge/origin/model/wires/get/widget/autofocus'
)).then(response => {
    if (response.payload.status !== 'ok') {
        throw new Error(response.payload.error);
    }
    return z_assets.ensure(response.payload.result);
});
```

Normally the widget manager performs this lookup and initializes the widget after loading. The asset loader shares loaded and pending files with lib tags and dynamic updates.

Configuration and errors
------------------------

Configuration module `mod_wires`, key `widget_autoload`, defaults to `true`. Setting it to `false` disables resolution through this model; explicitly included widgets continue to work.

| Error          | Meaning                                                              |
| -------------- | -------------------------------------------------------------------- |
| `disabled`     | Automatic widget loading is disabled for the site.                   |
| `badarg`       | The widget name is empty or contains unsupported characters.         |
| `enoent`       | The conventional library file is absent from the site library index. |
| `unknown_path` | The requested model path is not supported.                           |

This read-only model has no additional ACL restriction: it exposes descriptors for public library files. It does not accept arbitrary paths or URLs.

Direct Erlang calls to `m_get/3` return `{ok, {Assets, Rest}}` on success or `{error, Reason}` on failure. `Rest` contains any remaining model path segments.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/3096?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/3096?language=en>)
