LSPS documentation logo
LSPS Documentation
Validating UI Form Data

To validate a value during event processing of an event, define one of the following:

  • To validate literals of simple values entered in the form components, for example, a string in a text field, define a validator.
  • To validate record values, check if the value meets the record constraints by calling the validate() function. You can do so

Generally validation part of the event-processing cycle passes if:

  • all validators of the processed events return null and
  • data validations of the processed events do not return any validation constraint violations.

However, mind that for ValueChangeEvents it is enough if their own validation passes: ValueChangeEvents are queued for processing always when their validation passes. Other listeners are ignored. Consequently, the Execute if other validations failed setting of ValueChangeEvents is ignored.

On the other hand, the validity of ValueChangeEvents has no impact on the validity of non-ValueChangeEvents.

Example: Consider the form below:

  • The ISBN text box has a ValueChangeListener with a validator for the entered text.
  • The Submit button has an ActionListener with the Execute if other validations failed property set to false and executes submit (the Submit property is selected).

If the user enters an invalid ISBN and hits Submit, the form is submitted and the invalid ISBN value is persisted: the ActionListener on the Submit button ignores that the validation of the ChangeValueListener failed. To prevent the form submit in such cases, move the validation into the ActionListener.

inputValidationOnActionListener.png

Validating a Value of a UI Form Component

To validate a value of a simple data type automatically, use validator expressions: the expressions are checked automatically during the validation phase of they event processing)

To create validators and validate a value of a simple data type automatically, do the following:

  1. Open the listener that should cause the validation.
  2. On the Basic tab in the Validators section define the validator expressions: The expressions return a string with the error message when the validation fails, for example, if searchVar!=null and length(searchVar)>0 then null else “Provide search string!” end. The messsage is displayed as an error message either on the current component or on the component defined by their Error placement property.
minimumValidatorDef.png

Note: Mind that failed validation on ValueChangeListeners does not cause fail of the form validation: other listeners will still be processed. For further information refer to the section on validation

Validating a Record Value in a UI Form

To validate values of record properties entered in a form, define the Data Validation expression on the listener: the expression is checked during the validation phase of the event processing. If it returns a list of ConstraintViolations with messages, the messages are displayed on the components that are bound to the properties.

To obtain the list of violated constraints, call the validate() function.

If you need to display a constraint violation only on a particular component, create a constraint violation with a record or property set to the same binding as your component; for example: [new ConstraintViolation( payload -> null, record -> selectedRecord, property -> LookupValue.displayName, guid -> null, id -> null, message -> "Incorrect value.") ]

validatingwithvalidatecallandvalidator.png
Listener with validators and data validation

Note: Mind that if you define validation on ValueChangeListeners, the failure of the validation does not cause the overall form validation to fail: other listeners will still be processed. For further information refer to the section on validation

Defining Validation in Listener Handle

To perform validation manually from a Listener Handle expression, you will need to

  • collect a set of constraint violations, typically, by calling the validate() function on the respective Record,
  • call the showConstraintViolations() function to display the violations.

For further information on the functions and constraints, refer to the documentation on Record validation.

When validating a Record in the Handle expression of a Listener, do the following:

  1. Collect a list with constraint violations; typically you will use the validate() function on the record or property.
  2. Call showConstraintViolations() function to display the error messages of the violation on the respective form components.
validationinhandle.png
A record validated as part of a listener's Handle

Note: Mind that if you define validation on ValueChangeListeners, the failure of the validation does not cause the overall form validation to fail: other listeners will still be processed. For further information

Handling an Event When Validation Failed

To process a listener even if the form validation fails, select Execute if other validations failed of the listener.

It is enough that the validation on that particular listener passes for the event to be handled: failed validations on other listeners are ignored.

Filtering Validation Errors

When using validation of constraints on form components, by default, any validation errors are displayed on the form component that contains the value with the error. However, you can define explicitly which validation errors are displayed or ignored by the component on the Validation Errors tab of its properties:

  • Exclude Validation Error: intended for filtering of errors; only a subset of the errors is displayed on the component.
  • Include Validation Error: additional validation errors displayed on the component.

    Typically, you will include here errors that would otherwise remain hidden; for example, when editing multiple record fields, which result in an overall record constraint violation, the error for the entire record is not be displayed since there is no form component that references the entire record.

excludeValidationError.png
Including a Validation Error on a Form Component
If you want to ignore invalid data in a form and force processing of an event, select the Execute even if invalid components setting for the given listener: the listener will be always executed as part of the next event processing.

Validating Initialized Forms

To validate initialized forms, design the forms as follows:

  1. On the form, define an InitListener which fires an ApplicationEvent.
  2. Define an ApplicationEventListener that listens for the ApplicationEvent.
  3. On the ApplicationEventListener, define the validation expression.