Skip to main content

Validations in Widgets

This chapter describes how to configure validation rules for widget inputs in TSM. Each validation section lets you control when the input is required, apply rules such as regex patterns or length limits, and define custom validation expressions.


1. Required Field

Options

  • Required (Checkbox) Mark this checkbox if the input must be filled in.

    The form cannot be submitted if this input is empty.

  • Custom error message (Required) Define a custom error message shown when the field is required but left empty.

    • Example:

      This field is mandatory, please fill it in.
    • Default (if no message is entered):

      This value is required
  • Condition (JEXL) for enabling required Use a JEXL expression to control when this input becomes required. Logic: expression must return true → required, false → not required.

    Examples:

    $context.form.chars.checkbox == true

    → required only if a checkbox is ticked.

    !isNullOrEmpty(find($runtimeInfo.urList,'roleCode','Admin'))

    → required only if the user has role Admin.

    hasPriv('!Crm')

    → required only if the user has privilege Crm.


2. Pattern (Regex)

Options

  • Regex pattern (ECMAScript) Enter a regular expression to validate the input.

    Examples:

    ^[0-9]+$        → only digits
    ^[a-zA-Z]+$ → only letters
    ^[^@\s]+@[^@\s]+\.[^@\s]+$ → basic email format

    Test your regex online: regex101.com (ECMAScript)

  • Custom error message (Pattern) Define a custom error message if the input does not match the regex.

    • Example:

      Please enter a valid email address.
    • Default:

      The value entered does not match the regex [/^\d+$/]
  • Condition (JEXL) for enabling regex Decide when regex validation should be applied. Logic: expression must return true → regex active, false → skipped.

    Examples:

    $context.form.chars.email != null

    → regex only if email input is filled.

    hasPriv('!Crm')

    → regex only if user has Crm privilege.


3. Minimum Length

Options

  • Minimum length (Number) Define the minimum number of characters the input must contain.

    • Example: 3 → input must have at least 3 characters.
  • Custom error message (Min length) Define a custom error message when input is too short.

    • Example:

      At least 3 characters are required.
    • Default:

      The value ({{actualLength}}) does not have required minimum length {{requiredLength}}
  • Condition (JEXL) for enabling min length Control when min length validation is active. Logic: true → active, false → skipped.

    Examples:

    $context.form.chars.username != null

    → validate only if username is filled.

    nidValid($context.form.chars.idNumber)

    → validate only if the ID number field contains a valid birth number.


4. Maximum Length

Options

  • Maximum length (Number) Define the maximum number of characters allowed.

    • Example: 10 → input cannot exceed 10 characters.
  • Custom error message (Max length) Define a custom error message when input exceeds the maximum.

    • Example:

      Maximum 10 characters allowed.
    • Default:

      The value ({{actualLength}}) does not have required maximum length {{requiredLength}}
  • Condition (JEXL) for enabling max length Control when max length validation is applied. Logic: true → active, false → skipped.

    Examples:

    $context.form.chars.username != null

    → validate only if username is filled.

    $value.idDocumentNumber.length() <= 9

    → enforce max length 9 for document number field.


5. Custom Validations

Options

  • Custom error message (Custom validation) Define your own error message for this validation rule.

    • Example:

      Document number must not exceed 9 characters.
    • Default: none (no message is shown if left empty).

  • Expression (JEXL) for custom validation Create a JEXL expression for your own validation logic.

    Examples:

    $value.idDocumentNumber.length() <= 9

    → document number must not exceed 9 characters.

    nidValid($context.form.chars.birthNumber)

    → check if another field contains a valid birth number.

    $context.form.chars.checkbox == true

    → apply validation only if a checkbox is ticked.

  • Condition (JEXL) for enabling custom validation Control when custom validation is applied. Logic: true → validation active, false → skipped.

    Examples:

    ${row.country == 'US'}

    → apply validation only for US records.

    hasPriv('!Crm')

    → custom validation only if user has Crm privilege.


With these options, you can fully configure required fields, regex checks, min/max length restrictions, and your own custom validation rules in TSM.