formData.notify
(FintechOS Platform 24.2 and later)
Triggers a custom event (that was defined using the formData.registerEvent function).
Syntax
Copy
formData.notify(customEventName: string, payload?: any): void
| Parameter | Type | Description |
|---|---|---|
customEventName
|
string | Name of the triggered custom event. |
payload?
|
any | Input parameters for the event handlers' callback functions. |
Examples
In this example:
- We define two handlers called nameHandler and ageHandler that log the name and age properties of a payload object in the browser console when a custom event called myCustomEvent is triggered.
- We define the GetAge function that calculates a person's age based on the input date of birth. It computes the difference in years between the current date and the input date and adjusts the result if the current date is before the birthday in the current year.
- We use the formData.model method to populate the payload object with the person's name and age based on the current form's input fields.
- We trigger the custom event so that the person's age and name are logged in the console. The registered event handlers (logName and logAge) are called with the payload as their argument.
Copy
var customEventName= 'myCustomEvent';
var logName = function(payload){
console.log('Hello ' + payload.name + '.');
}
var logAge = function(payload){
console.log('You are ' + payload.age + ' years old.');
}
var nameHandler = formData.registerEvent(customEventName, logName);
var ageHandler = formData.registerEvent(customEventName, logAge);
function GetAge(inputDate) {
var today = new Date();
var age = today.getFullYear() - inputDate.getFullYear();
var m = today.getMonth() - inputDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < inputDate.getDate())) {
age--;
}
return age;
};
var payload = {
name: formData.model.name,
age: GetAge(formData.model.birthDate)
};
formData.notify(customEventName, payload);