Master Show
In this example, we will show you how you can use the UI Builder API to get and set your Field ID values, Get the Payload as well as Save Pages.
This can be useful, for example, if you need to get or update a specific value from another template or page.
The example UI takes in a Field ID and value. the Field ID is the ID of the UI component you want to get and set. the Value is the new value of the Field ID.
The example UI also can Print the Payload, as well as Save Pages using the UI Builder API.
Info
This page mixes the two event styles UI Builder supports. control.on('change', callback) adds a listener, so several handlers can react to the same event, while control.onChange = callback replaces whatever handler was assigned before. They are otherwise equivalent.
Getting the value of a Field ID
To get the value of a Field ID, this can be done by calling the code Api.page.getFieldValue('FieldID'), this takes in one parameter, the Field ID.
1 2 3 | |
Setting the value of a Field ID
To set the value of a Field ID, this can be done by calling the code Api.page.setFieldValue('FieldID', value), this takes two parameters, the FieldID which will be the reference for what is to be updated, and the value which will be the new value of the FieldID.
1 2 3 | |
Tip
Api.page.setFieldsValue({ FieldA: 'x', FieldB: 'y' }) sets several fields in a single call.
Saving Page using the UI Builder API
Users can also save pages using the API:
Api.page.save(num?, name?, overwrite?)saves the current page, optionally renumbering and renaming it.Api.page.saveAs(num?, name?, overwrite?)always creates a new page.
All three arguments are optional on both calls.
Warning
num must be digits only. A string that contains anything else throws Page Num has to be digits only, and so does a value that is neither a string, a number nor undefined. The sample below feeds a control value straight in, so wrap the call in try/catch if the operator can type into that control.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
saveAs also accepts a single options object, which is the only way to control where the new page is inserted:
1 2 3 4 5 6 | |
Calling the Payload using UI Builder API
To call the Payload, users can call Api.page.payload
1 2 3 | |
The rest of the Page API
Besides the calls above, Api.page exposes tabToField(field), the storage object, and the writable properties name, description, num, channel, readOnly and color. See Pages for the full reference and Set Page info from Code for an example of the properties.
