Custom component - CustomComponent
The custom component (CustomComponent) allows you to create your own components for the application using the language JavaScript.
A CustomComponent consists of eight elements:
JavaScript script,
Component CSS styles,
Component HTML template,
Component input parameter mappings,
List of used services,
List of actions available for this component,
Translations of texts for the component,
Preview.
Creating a component
A new component is created in the same way as other components. After going to the Library module and selecting the Custom components tab, click the Add custom component button and in the opened window set the name and location of the artifact being created (More information about the editor itself: Custom components editor)

JavaScript script
Each CustomComponent consists of one main function, to which the Scope of the component is passed:
Using the scope, the creator can, among other things, retrieve component data, input data, and react to certain events from the component lifecycle. The user can implement three system component methods:
afterViewInit - executed when the component is added to the application's DOM structure,
onModelChange - executed when the model (e.g. value) of the component or the input data value changes,
onDestroy - executed when the component is removed from the application's DOM structure.
Additionally, the component scope provides several useful elements:
fields:
domId - component ID in the application's DOM structure
componentId - component ID
componentMid - component MID
visible - variable controlling component visibility
translations - translation map defined at the component creation stage
componentId - map of component input parameters
componentData - map of internal component data (allows the component state to be preserved)
componentInput - map of component input data (keys are defined in the Inputs section, separated by commas)
methods:
getValue() - retrieves the current value of the component
setValue(value) - sets the current value of the component
querySelector(query) - returns the DOM element of the component that matched the selector.
putData(key, value) - sets the specified value (value) under the key (key) in the component data map - browser client side only
saveData(key, value) - sets the specified value (value) under the key (key) in the component data map - also on the server side
getData(key) - retrieves the value specified under the key (key) in the component data map
translate(key) - returns a translation from the translation map
clean() - clears the scope object when it is no longer used by the CustomComponent
callServiceProxy(serviceName, params) - allows calling ServiceProxy and ScriptService services synchronously
callServiceProxyAsync(serviceName, params) - allows calling ServiceProxy and ScriptService services asynchronously
initTooltip(id, element, data) - allows initializing a tooltip with the given identifier (required value, must meet all HTML ID attribute requirements) on the passed element
showTooltip(id) - shows the tooltip with the given id
hideTooltip(id) - hides the tooltip with the given id
destroyTooltip(id) - destroys the tooltip with the given id
destroyAllTooltips() - destroys all tooltips of the given component
goForward() - navigates to the next (allowed) page or submits the application (when the user is on the last page of the application)
goBackward() - navigates to the previous (allowed) page
setInactiveForward() - sets the button navigating to the next page to inactive (Feature availability depends on the license and may not be available in all deployments.)
setActiveForward() - sets the button navigating to the next page to active (Feature availability depends on the license and may not be available in all deployments.)
triggerCustomEvent(eventName) - allows triggering a CustomEvent previously defined for a given component
sendCurrentValueEvent() - sends an event containing the current value of the CustomComponent along with its id
isPageValid() - returns information whether there are validation errors on the page
Component interfaces
Example component function
In the above example, a component was defined that displays a Popup on the application with information about a positive credit decision:

In line 6, the system function was defined afterViewInit initializing the buttons X and NEXT, as well as controlling the window visibility. In line 2, a function executed when one of the two buttons is clicked was defined.
Popup DOM structure:
In the component template definition, you can refer to defined translations using the convention _{TRANSLATION_KEY} - example in line 5.
Calling scripts or ServiceProxy
From a CustomComponent, you can call ServiceProxy and ScriptService services using the methods callServiceProxy and callServiceProxyAsync. Both methods return Observable with response in the following format:
To get the response you need to call the .subscribe() method known from RxJS. As in RxJS, it is also worth calling unsubscribe() at the appropriate time on the returned object. For example, unsubscribe can be called in the onDestroy.
When using ServiceProxy or ScriptService, you need to add it to the list of used services on the CustomComponent:

Component input fields
In the Input data section, the IDs of the component input fields are defined. IDs should not contain spaces.

The defined input fields can be fed by other application components in the same way as complex components (ComplexComponent) - by mapping the appropriate data in the INPUT PARAMETERS:

Translations
Dedicated internationalized texts are defined in the Component translationssection, which appears after selecting the Translations.

In this view, the key and default value of the text handled in the CustomComponent are defined. Text translations in the required languages are defined in the standard way on the application to which the component has been attached.
Example of adding a translation key:
After clicking the Add translation button at the bottom of the panel, add a translation key and a default value:

Figure 6b. Adding a new key and translation The added translation key can be used in the CustomComponent DOM structure:

After adding the CustomComponent to the application or to a complex component in the Translations tab, the keys from the CustomComponent will appear. They can also be added manually.

Handling messages
To make the CustomComponent handle validation messages itself, select the option in the parameters section Custom error message display. This option allows message handling via the method onMessagesUpdate.

Defining custom events for the component
For each CustomComponent, individual actions can be defined (CustomEvents). They are attached and handled in the same way as standard events defined in the platform. The action definition looks as follows:

Actions defined in this way can be attached on the application to a given action. For example, the TEST_EVENT_A action is used to open the popup:

The event itself can be invoked inside the CustomComponent's JS script using the triggerCustomEventmethod, for example:
Component simulation
To check the operation of the created CustomComponent, you can use the simulation function. To do this, click the Previewbutton located on the right side of the screen. Clicking it changes the screen to simulation mode. On the left side you will see the JavaScript, CSS and HTMLwindows, and on the right the component parameters (provided that input parameters have been defined). After starting the preview, we can feed the component with variables retrieved in the component and observe its behavior without having to embed it in the application and run it in the development environment.

If we want changes in the preview to be shown live, before filling in the component parameter field values it is worth selecting the option Automatic refresh. After filling in all fields, click the Refreshbutton. The fields with entered values will then hide, and the component view will appear. You can always show the filled-in parameters by clicking the option with the number of parameters and the label (show).

After clicking the Preview button again, we return to the standard component view with the list of parameters on the left side.
Embedding in the application
The created CustomComponent is embedded in the application/in a complex component by adding it from the component palette. To do this, click the Add component button in the left sidebar and in the slid-out component panel select the Customtab, which is available after clicking the symbol
. A list of CustomComponents available in the repository will be displayed.
At the top of the panel there is a search field that makes it easier to find the artifact to embed. Adding the component consists of dragging it from the palette and dropping it in the appropriate place on the application.

After embedding the component in the application, you need to feed the component input fields (defined according to the Input fields of the componentsection) by clicking in the Basic properties option INPUT PARAMETERS:

Controlling the activity of the button navigating to the next page
In the JavaScript tab of the edited CustomComponent, we can use the methods:
setInactiveForward() - sets the button navigating to the next page to disabled
setActiveForward() - sets the button navigating to the next page to active
It should be remembered that calling the method setInactiveForward inside afterViewInit will disable the button after every change in component visibility - therefore this should be taken into account in the implementation.
The button's activity can be made dependent on the channel in which the request is displayed using a conditional statement if , taking session variables into account channel and channelDescription (remember to map them to the component beforehand).
Calling the native API
The $scope object provides the function callNative, which takes a function whose parameter is a native API object (signature: callNative(nativeFunction: (api: NativeAppApi) => any): void). The api object has a defined interface provided by the eximee platform. The function requested on the native object will be called only if this object is available in the context.
Controlling the platform loader
On the window object, methods are available that allow controlling the platform loader:
startSpinner() - turns on the loader
stopSpinner() - turns off the loader
Last updated
Was this helpful?
