s_widget is an object of the SimpleWidget class initialized within a widget you create.

s_widgets is an object of the SimpleWidgets class initialized when you add a widget to a form or a portal page.

The widget API describes methods and custom method declarations for widget structure and functionality customization:

  • Use s_widget and s_widgets methods in client-side scripts to implement the widget functionality you need.
  • If you need to create your own widget methods, use the custom method functionality.

These methods can be used on the client-side only.

s_widget


To perform the current widget customization you created, use the methods below.

Manual console invoke

In the console, to manually invoke the method, pass the widget instance ID as the first parameter. Ex., to call the following method:

s_widget.getFieldValue(key); 

use the method instead:

s_widget.getFieldValue(widgetId, key);


s_widget.addTemplate(id, template, script, type)


This method adds a child template to the existing template by its ID with one of the following types: inner, before, after.

Parameter(s):

NameTypeMandatoryDefault Value
idStringYN
templateStringYN
scriptString

This parameter is mandatory if you need to define the type parameter. If no script needed, then use an empty string ('') as in the example below.

N
typeString (possible options: inner, before, after)Y

inner 

Return:

TypeDescription
VoidThis method does not return value.

Example:

Add to a template field:
<div id="steps"></div>
Add to a client script
s_widget.addTemplate('steps', '<div class="main">', '', 'inner');

s_widget.getElements()


This method returns the element structure of a widget.

Return:

TypeDescription
array<elements>The widget structure elements are collected in an array.

Example:

s_widget.getElements()
window.s_widget.getElements();

s_widget.getFieldValue(key)


Use this method to return the widget field value defined by the key option.

Parameter(s):

NameTypeMandatoryDefault Value
keyStringYN

Return:

TypeDescription
mixedThe value of the field is defined by the key defined.

Example:

s_widget.getFieldValue
s_widget.getFieldValue('element');

s_widget.getForm()


This method returns a form object that is placed using the <Form> or <remform> tags.

Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN

Return:

TypeDescription
ObjectThis method returns a SimpleForm object.

Example:

s_widget.getOptionValue
const builtInForm = s_widgets.getForm('custom');
await builtInForm.save();

s_widget.getId()


This method returns a widget instance ID as a string value.

Return:

TypeDescription
StringThis method returns a widget instance ID.

Example:

s_widget.getId
s_widget.getId();

s_widget.getOptionValue(key)


Use this method to return the widget option value defined by the key option.

Parameter(s):

NameTypeMandatoryDefault Value
keyStringYN

Return:

TypeDescription
mixedThe value of the widget options is defined by the key.

Example:

s_widget.getOptionValue
s_widget.getOptionValue('label');

s_widget.removeTemplate(id)


The method removes all child nodes and content from specified elements. It does not remove the element itself or its attributes.

Parameter(s):

NameTypeMandatoryDefault Value
idStringYN

Return:

TypeDescription
VoidThis method does not return value.

Example:

Add this to the Template field
<div id="element1">
  Remove me
</div>
<button buttonType="approve" event-click="window.s_widget_custom.remove();">
  Click me
</button>
Add this to the CSS field
#element1 {
  background-color: yellow;
  height: 20px;
}
Add this to the Client Script field
;
(() => {
    window.s_widget_custom = window.s_widget_custom || {};
    window.s_widget_custom.remove = function () {
        s_widget.removeTemplate('element1');
    } 
})();

s_widget.setFieldValue(key, value)


This method sets the value using the key.

If the value parameter is equal to 'null' , for example, s_widget.setFieldValue ('subject', null), the defined field will be cleared.

Parameter(s):

NameTypeMandatoryDefault Value
keyStringYN
valuemixedYN

Return:

TypeDescription
VoidThis method does not return value.

Example:

s_widget.setFieldValue
;
(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();
})();


s_widget.serverUpdate()


This method transfers widget data to a server script and updates widget data according to the server reply.

Return:

TypeDescription
ObjectThis method returns a promise containing specific data.

Example:

s_widget.serverUpdate
;
(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);
})();

s_widget.setOptionValue(key, value)


This method sets the widget option value using the key option.

Parameter(s):

NameTypeMandatoryDefault Value
keyStringYN
valuemixedYN

Return:

TypeDescription
VoidThis method does not return value.

Example:

s_widget.setOptionValue
s_widget.setOptionValue('label', 'name');

s_widget.showData()


The method displays the field data of a widget in the console. 

Return:

TypeDescription
Void

This method does not return value.

Example:

s_widget.showData
s_widget.showData();

s_widgets


Invoke the s_widgets methods within your scripts, when adding a widget to a form, a page or for widgets interaction.

s_widgets.getFieldValue(widgetInstanceID, key)


This method returns the object value using the key and widget instance ID.

Parameter(s):

NameTypeMandatoryDefault Value
widgetInstanceIDString (the sys_id value)YN
keyIntegerYN

Return:

TypeDescription
mixedReturns the object value.

Example:

s_widgets.getFieldValue
s_widgets.getFieldValue('157555401214600424', 'name');

s_widgets.getWidgets()


This method returns all the widget instance IDs of the page.

Return:

TypeDescription
List<String>List of ID objects of String type. 

Example:

s_widgets.getWidgets
s_widgets.getWidgets();

s_widgets.setFieldValue(widgetInstanceID, key, value)


This method sets the value using the key and the widget instance ID.

Parameter(s):

NameTypeMandatoryDefault Value
widgetInstanceIDString (the sys_id value)YN
keyIntegerYN
valuemixedYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

s_widgets.setFieldValue
s_widgets.getFieldValue('157555401214600424', 'name', 'Alex');

s_widget_custom


Within the client-side scripts, you can configure your own widget methods by using the window.s_widget_custom variable:

Ex.
window.s_widget_custom.updateFullname = function() {
  //
}

  • No labels

1 Comment

  1. Anonymous

    s_widget.addTemplate('steps', '<div class="main">, ''. 'inner');
    опечатка, должно быть 
    s_widget.addTemplate('steps', '<div class="main">', '', 'inner');