Add Custom Validation Rules

See SAIL Recipes for information about how to work through recipes and adapt them to your application.

Goal

Enforce that the user enters no more than a certain number of characters in their text field, e.g. to match the size constraint on a database column.

image:Custom_Validation_.png

Expression

=load(
  local!varA,
  local!varB,
  a!formLayout(
    label: "SAIL Example: Custom Validation Rules",
    firstColumnContents:{
      a!textField(
        label: "5 Characters",
        instructions: "Character count: " & len(local!varA) & "/5",
        value: local!varA,
        saveInto: local!varA,
        refreshAfter: "KEYPRESS",
        validations: if(len(local!varA)<=5, null, "Enter no more than 5 characters")
      ),
      a!textField(
        label: "Text",
        value: local!varB,
        saveInto: local!varB,
        validations: "Any text you enter is invalid"
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: a!buttonWidgetSubmit(
        label: "Submit"
      )
    )
  )
)

Test it out

  1. Type more than 5 characters in the first text field to see the validation message. The form cannot be submitted while the validation message is displayed.
    • Notice that the second text component doesn't show the validation message until the user types into it. This is because the text value isn't considered invalid until it has a value. See also: Validating User Inputs
    • When testing offline, the form queues for submission but returns the validation messages when you go back online and the form attempts to submit.

To write your data to process

  1. Save your interface as sailRecipe
  2. Create interface inputs: varA (Text), varB (Text)
  3. Remove the load() function
  4. Delete local variables: local!varB, local!varB
  5. In your expression, replace:
    • local!varA with ri!varA
    • local!varB with ri!varB
  6. In your process model, on the process start form or forms tab of an activity, enter the name of your interface in the search box and select it
  7. Click Yes when the process modeler asks, "Do you want to import the interface inputs?"
    • On a task form, this will create create node inputs
    • On a start form, this will create parameterized process variables
FEEDBACK