Spanish Total.js
English
Documentation For AI agents
Contents

Settings and the settings form

Default settings, the fields of the settings form and how the component reacts to changes.

.md GitHub
On this page

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>

The settings of a Stepper: Name, Read value from, Minimum, Maximum and Step

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:

configField
(none)A text field.
type:checkboxA checkbox, for a true or false setting.
type:numberA number.
type:iconAn icon picker.
type:colorA colour picker.
dirsource:a|First,b|SecondA list of fixed options: the value, a bar and the text.
dirsource:#inputsA list of the inputs of the design.
dirsource:#outputsA list of the outputs of the design.
dirsource:#datasourceA list of data sources: components that others can follow, code lists and data views.
required:1The field must not be empty.
placeholder:TextA 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.settingsForm
'auto'settings.html next to editor.html.
An addressThe file at that address.
HTMLThe 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
});
Made in Europe