Settings and the settings form
Default settings, the fields of the settings form and how the component reacts to changes.
The settings of an instance are in config, the second argument of exports.make. They start as a copy of exports.config and change when the user submits the settings form.
Default settings
exports.config = { min: 0, max: 10, step: 1 };Every new instance starts with these values. The configuration also holds name, the Name of the instance, and path, the Read value from field when the user sets it.
The settings form
The form is made of Total.js UI components. Each field has a path that starts with ?. followed by the key in the configuration:
<div class="padding">
<div class="grid-3">
<div class="m">
<ui-component name="input" path="?.min" config="type:number">Minimum</ui-component>
</div>
<div class="m">
<ui-component name="input" path="?.max" config="type:number">Maximum</ui-component>
</div>
<div class="m">
<ui-component name="input" path="?.step" config="type:number;required:1">Step</ui-component>
</div>
</div>
</div>
UI Builder puts Name and Read value from above your fields, and the SUBMIT and Cancel buttons below them.
Kinds of fields
The input component takes its kind from config. These are used by the official components:
config | Field |
|---|---|
| (none) | A text field. |
type:checkbox | A checkbox, for a true or false setting. |
type:number | A number. |
type:icon | An icon picker. |
type:color | A colour picker. |
dirsource:a|First,b|Second | A list of fixed options: the value, a bar and the text. |
dirsource:#inputs | A list of the inputs of the design. |
dirsource:#outputs | A list of the outputs of the design. |
dirsource:#datasource | A list of data sources: components that others can follow, code lists and data views. |
required:1 | The field must not be empty. |
placeholder:Text | A hint in an empty field. |
Join several with ;, for example type:number;required:1. For a field that appears only for some values of another field, wrap it in <ui-bind path="?.type" config="show:value==='number'">, as Textbox does.
Where to put the form
exports.settings | Form |
|---|---|
'auto' | settings.html next to editor.html. |
| An address | The file at that address. |
| HTML | The form itself, for example '<div class="padding"><ui-component name="input" path="?.title">Title</ui-component></div>'. |
A <settings> part in editor.html works too. A component without settings shows only Name and Read value from.
React to changes
In the editor, UI Builder emits configure after the user submits the form. The handler receives the previous values of the keys that changed.
instance.on('configure', function(changes) {
element.find('.title').text(config.title);
});
instance.emit('configure');configure does not run when the instance is created, so call it once yourself, as above. In a published design the settings do not change.
To change the settings before the form opens, handle settings. It receives a copy of the configuration that the form will edit:
instance.on('settings', function(config) {
// change config for the form
});