Spanish Total.js
Italiano
Documentazione Per agenti IA
Indice

Write a component with a setting

Create a component that changes one field of a message, with a setting to choose the field.

.md Sito web

Questa pagina non è ancora tradotta. Stai leggendo l’originale.

In questa pagina

This recipe builds Uppercase, a component that turns one text field of the incoming object into capital letters. A setting lets you choose the field.

Create the component

1. Select Add (plus), then Create new component.

2. Replace the whole template with this code:

<script total>

    exports.id = 'uppercase';
    exports.name = 'Uppercase';
    exports.icon = 'ti ti-font';
    exports.author = 'Demo project';
    exports.version = '1';
    exports.group = 'Demo';
    exports.config = { field: 'name' };
    exports.inputs = [{ id: 'input', name: 'Input' }];
    exports.outputs = [{ id: 'output', name: 'Output' }];

    exports.make = function(instance, config) {
        instance.message = function($) {
            var data = $.data;
            if (data && typeof(data[config.field]) === 'string')
                data[config.field] = data[config.field].toUpperCase();
            $.send('output', data);
        };
    };

</script>

<readme>
Changes one text field of the incoming object to capital letters.
</readme>

<settings>
    <div class="padding">
        <ui-component name="input" path="?.field" config="required:1">Field name</ui-component>
    </div>
</settings>

<body>
    <header>
        <i class="ICON"></i>NAME
    </header>
</body>

3. Select APPLY. Uppercase appears in the Demo group on the left.

Use it

  1. Set the Trigger to send an object, as in Your first flow.
  2. Drag Uppercase onto the canvas.
  3. Connect Trigger to Uppercase, and Uppercase to Print.
  4. Select APPLY and confirm.
  5. Select Run on the Trigger.

Print shows the object with the name in capital letters. Double-click the Uppercase node to choose another field.

A Trigger connected to Uppercase and Print, which shows JANE DOE

Share it

Save the code as uppercase.html. You can drop the file on another FlowOS, or put it on a web server and install it with Link component. See Add components.

To learn more about the component format, see the Flow development guide.

Fatto in Europa