Skedulo Plus extensions validation rules

How to add validation to your mobile extensions.

Overview

Validation is an important part of the UI application. It allows the UI to validate user inputs in real time.

To use validation, the component must support the validation object. You can find these in the property tables on each of the page component pages.

Validation example

The purpose of this object is to return a key from a localized string (with a value if there is an error, or null if there is no error) to the consumer (element).

[{
    "type": "expression",
    "expression": "pageData.quantity > 0",
    "errorMessage": "en.UpsertForm.QuantityMustBeAbove0"
},
{
    "type": "customFunction",
    "functionName": "myFunction"
}]

Types of rules

Abstract rule

Abstract rules mean that all rules have the same properties as the abstract rule.

Property Description
type Type of rule. Only expression is supported at present.

Expression rule

Required rules check if the value passed inside has a value or not.

Property Description
expression Expression string to return a Boolean value that indicates if it is valid or not.
errorMessage Error message to be returned for the element. It’s a localized expression key.

Example:

The following could be used to validate that a quantity is above 0 and display an error message quantity_must_be_above_0 if it is not. The message can be further translated using localization.

  {
      "type": "expression",
      "expression": "pageData.quantity > 0",
      "errorMessage": "quantity_must_be_above_0"
  }

Custom function rule

A custom function can be used just as you would an expression:

{
      "type": "expression",
      "expression": "cf.checkStatus(pageData.Status)",
      "errorMessage": "status_must_be_valid"
  }

The checkStatus method works as follows:

function checkStatus(status, {extHelper}): boolean {
    return status != 'Rejected' ? true : false
}
let expoertFns = {
    checkStatus: checkStatus
}

Attributes of the method

  • The method must return a boolean.
  • The method must be a synchronous (no promise) method