Uses of custom functions

Advantages of using custom functions in Adaptive Forms are:

  • Manipulation of data: Custom functions manipulate and process data entered into the forms fields.
  • Validation of data: Custom functions enable you to perform custom checks on form inputs and provide specified error messages.
  • Dynamic behavior: Custom functions allow you to control the dynamic behavior of your forms based on specific conditions. For example, you can show/hide fields, modify field values, or adjust form logic dynamically.
  • Integration: You can use custom functions to integrate with external APIs or services. It helps in fetching data from external sources, sending data to external Rest endpoints, or performing custom actions based on external events.

Supported JS annotations

Ensure that the custom function you write is accompanied by the jsdoc above it, in case, you require custom configuration and description. There are multiple ways to declare a function in JavaScript, and comments let you keep a track of the functions. For more information, see usejsdoc.org.

Supported jsdoc tags:

  • Private
    Syntax: @private
    A private function is not included as a custom function.

  • Name
    Syntax: @name funcName <Function Name>
    Alternatively , you can use: @function funcName <Function Name> or @func funcName <Function Name>.
    funcName is the name of the function (no spaces allowed).
    <Function Name> is the display name of the function.

  • Member
    Syntax: @memberof namespace
    Attaches a namespace to the function.

  • Parameter
    Syntax: @param {type} name <Parameter Description>
    Alternatively, you can use: @argument {type} name <Parameter Description> or @arg {type} name <Parameter Description>.
    Shows parameters used by the function. A function can have multiple parameter tags, one tag for each parameter in the order of occurrence.
    {type} represents parameter type. Allowed parameter types are:

    1. string
    2. number
    3. boolean
    4. scope

    Scope is used for referring fields of an Adaptive Form. When a form uses lazy loading, you can use scope to access its fields. You can access fields either when the fields are loaded or if the fields are marked global.

    All other parameter types are categorized under one of the above. None is not supported. Ensure that you select one of the types above. Types are not case sensitive. Spaces are not allowed in the parameter name. <Parameter Descrption> <parameter> can have multiple words. </parameter>

  • Return Type
    Syntax: @return {type}
    Alternatively, you can use @returns {type}.
    Adds information about the function, such as its objective.
    {type} represents the return type of the function. Allowed return types are:

    1. string
    2. number
    3. boolean

    All other return types are categorized under one of the above. None is not supported. Ensure that you select one of the types above. Return types are not case sensitive.

  • This
    Syntax: @this currentComponent

    Use @this to refer to the Adaptive Form component on which the rule is written.

    The following example is based on the field value. In the following example, the rule hides a field in the form. The this portion of this.value refers to underlying Adaptive Form component, on which the rule is written.

       /**
       * @function myTestFunction
       * @this currentComponent
       * @param {scope} scope in which code inside function will be executed.
       */
       myTestFunction = function (scope) {
          if(this.value == "O"){
                scope.age.visible = true;
          } else {
             scope.age.visible = false;
          }
       }
    
    NOTE
    Comments before custom function are used for summary. Summary can extend to multiple lines until a tag is encountered. Limit the size to a single for a concise description in the rule builder.