Extensibility forms module - Form validation

The K2BTools Extensibility Forms module provides a robust set of standard validations to ensure the integrity and consistency of data entered by end users. These validations are implemented in the code found in the validation folder inside the K2BTools.Controls.DynamicForm module. You can use these validations as provided or enhance them to fit your specific requirements.

Standard Validation Process

1. Structure Validation

  • Field Existence:
    When data is received, it is first compared against the current structure of the form.

    • If the data contains values for fields that no longer exist in the form, or for fields that have never existed, those values are discarded and an error is shown.

2. Field Type Validations

  • Character Fields:

    • The length of the entered value is validated to ensure it does not exceed the maximum allowed for the field.

  • Numeric Fields:

    • The value is validated using a regular expression to ensure it is a valid number.

    • The number of decimal places is checked to match the field’s definition.

  • Date Fields:

    • The value is parsed to confirm it is a valid date.

  • Combo Box Fields:

    • The value received is compared against the available options in the combo box.

    • This ensures that only valid, predefined values are accepted.

    • The same validation applies when the combo box is a collection (i.e., multiple selections).

3. Condition Validation

  • After the basic validations, any conditions defined in the form are evaluated.

    • Each condition must return true for the data to be considered valid.

    • If a condition does not return true, the error message associated with that condition will be shown to the user.

    Note:
    The parser used to process these conditions is not the same as the one used in GeneXus.
    We recommend using parentheses generously to clearly indicate operator precedence in your conditions.

Sample Conditions

Here are some examples of common conditions you can define:

  • Variable not empty:

    plain text

    not VariableName = ''

    Checks that the field is not empty.

  • Variable greater than 0:

    plain text

    VariableName > 0

    Checks that the value entered is greater than zero.

  • Variable greater than 0 and lower than 10:

    plain text

    (VariableName > 0) AND (VariableName < 10)

    Checks that the value is greater than zero and less than ten.

Validation of Sublevels (Collections)

If the form contains collections (sublevels that are collections), the structural validations (structure, field type) are recursively applied to each item in the collection. This ensures that every entry within a collection adheres to the same validation rules as the main form fields.

Extending Validations

You can enhance or customize the standard validations by modifying the code in the validation folder of the K2BTools.Controls.DynamicForm module to suit your specific business rules or requirements.

Best Practices

  • Always validate and sanitize user input before processing or storing it.

  • Use clear and descriptive error messages to help users correct their input.