The widget API describes the methods for widget structure and functionality customization:
Note |
---|
s_widget is an object of the SimpleWidget class that becomes available when a widget you create is initialized. s_widgets is an object of the SimpleWidgets class, initialized when you add a widget to a form or a portal page. |
To perform the current widget customization, use the methods below.
Info |
---|
In the console, to manually invoke the method, pass the widget instance ID as the first parameter. For example, to call the following method: Code Block |
---|
| s_widget.getFieldValue(key); |
use the following approach: Code Block |
---|
| s_widget.getFieldValue(widgetId, key); |
|
This method adds a child template to the existing template by its ID with one of the following types: inner, before, after.
Parameters:
Name | Type | Mandatory | Default value |
---|
id | String | Y | N |
template | String | Y | N |
script | String | N Note |
---|
This parameter is mandatory if you need to define the type parameter. If no script is needed, use an empty string ('') as in the example below. |
| N |
type | String (possible options: inner, before, after) | N | |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | xml |
---|
title | Add to a template field: |
---|
|
<div id="steps"></div> |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Add to a client script |
---|
|
s_widget.addTemplate('steps', '<div class="main">', '', 'inner'); |
This method returns the widget structure elements collected in an array.
Return:
Type | Description |
---|
array<elements> | The widget structure elements are collected in an array. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.getElements() |
---|
linenumbers | true |
---|
|
s_widget.getElements(); |
Use this method to return the data value of the widget that is defined by the key option.
Parameter:
Name | Type | Mandatory | Default value |
---|
key | String | Y | N |
Return:
Type | Description |
---|
Any | The value of the field that is defined by the key. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.getFieldValue |
---|
linenumbers | true |
---|
|
s_widget.getFieldValue('element'); |
This method returns a widget instance ID.
Return:
Type | Description |
---|
String | This method returns a widget instance ID. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.getId |
---|
linenumbers | true |
---|
|
s_widget.getId(); |
Use this method to return an option value that is defined by the key.
Parameter:
Name | Type | Mandatory | Default value |
---|
key | String | Y | N |
Return:
Type | Description |
---|
Any | A value of the widget option that is defined by the key. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.getOptionValue |
---|
|
s_widget.getOptionValue('label'); |
The method removes all child nodes and content from the specified element. It does not remove the element itself or its attributes.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
id | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | xml |
---|
theme | Eclipse |
---|
title | Add this to the Template field |
---|
linenumbers | true |
---|
|
<div id="element1">
Remove me
</div>
<button buttonType="approve" event-click="window.s_widget_custom.remove();">
Click me
</button> |
Code Block |
---|
language | css |
---|
theme | Eclipse |
---|
title | Add this to the CSS field |
---|
linenumbers | true |
---|
|
#element1 {
background-color: yellow;
height: 20px;
} |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Add this to the Client Script field |
---|
linenumbers | true |
---|
|
;
(() => {
window.s_widget_custom = window.s_widget_custom || {};
window.s_widget_custom.remove = function () {
s_widget.removeTemplate('element1');
}
})(); |
Use this method to set a value for the key.
Info |
---|
If the value parameter is equal to 'null', for example, s_widget.setFieldValue ('subject', null) , the defined field is cleared. |
Parameters:
Name | Type | Mandatory | Default value |
---|
key | String | Y | N |
value | Any | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.setFieldValue |
---|
linenumbers | true |
---|
|
;
(async () => {
const tableName = s_form.getTableName();
const recordId = s_form.getUniqueValue();
const serviceId = s_form.getValue('service');
const serviceDisplayValue = s_form.getDisplayValue('service');
s_widget.setFieldValue('table_name', tableName);
s_widget.setFieldValue('record_id', recordId);
s_widget.setFieldValue('service', { database_value: serviceId, display_value: serviceDisplayValue });
await s_widget.serverUpdate();
})(); |
With this method you can transfer the data to a server, where the widget server script runs. As a result, the widget data is updated.
Return:
Type | Description |
---|
Object | This method returns a promise containing a server response. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.serverUpdate |
---|
linenumbers | true |
---|
|
;
(async () => {
const tableName = s_form.getTableName();
const recordId = s_form.getUniqueValue();
s_widget.setFieldValue('table_name', tableName);
s_widget.setFieldValue('record_id', recordId);
const response = await s_widget.serverUpdate();
console.log(response.getData().data);
})(); |
Use this method to set a value using the key of the widget option.
Parameters:
Name | Type | Mandatory | Default value |
---|
key | String | Y | N |
value | Any | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.setOptionValue |
---|
|
s_widget.setOptionValue('label', 'name'); |
The method displays the data of a widget in the console.
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widget.showData |
---|
|
s_widget.showData(); |
Invoke the methods of the s_widgets object within your scripts, when adding a widget to a form or a page for widget interaction.
This method returns the data value of the widget for the key and widget instance ID.
Parameters:
Name | Type | Mandatory | Default value |
---|
widgetInstanceID | String (the sys_id value) | Y | N |
key | String | Y | N |
Return:
Type | Description |
---|
Any | Returns the object value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widgets.getFieldValue |
---|
|
s_widgets.getFieldValue('157555401214600424', 'name'); |
This method returns a form object that is placed using the <form> or <remform> tag.
Parameter:
Name | Type | Mandatory | Default value |
---|
name | String | Y | N |
Return:
Type | Description |
---|
Object | This method returns a SimpleForm object. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widgets.getForm |
---|
linenumbers | true |
---|
|
const builtInForm = s_widgets.getForm('custom');
await builtInForm.save(); |
This method returns a list of all the IDs of the widgets instances located on the page.
Return:
Type | Description |
---|
Array | A list of all the IDs of the widgets instances located on the page. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widgets.getWidgets |
---|
|
s_widgets.getWidgets(); |
Use this method to set a value for the key in the widget data, and the widget instance ID.
Parameters:
Name | Type | Mandatory | Default value |
---|
widgetInstanceID | String (the sys_id value) | Y | N |
key | String | Y | N |
value | Any | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | s_widgets.setFieldValue |
---|
|
s_widgets.setFieldValue('157555401214600424', 'name', 'Alex'); |