Validation - AtlasOfLivingAustralia/ecodata-client-plugin GitHub Wiki

Basic validation

Form elements rendered by the ecodata-client-plugin depend on the jQueryValidationEngine library for validation functionality. https://github.com/posabsolute/jQuery-Validation-Engine

Validation constraints for a data model item are specified by the "validate" attribute.

{ 
    "name":"item1",
    "dataType":"number",
    "validate":"min[0],max[100]"
}

The accepted values for this attribute are defined by the jQueryValidationEngine library. The renderer will automatically specify "custom[number],min[0]" for data items with a "number" "dataType". " min[0]" will only be included if it is not specified in the "validate" attribute. 'number', 'integer', 'url', 'date', 'phone' can all be included without the enclosing custom[], which will be added by the framework.

Conditional validation

The validation attributes assigned to a field can be dynamically changed based on an expression as per the example below:

    {
      "dataType": "number",
      "name": "item1",
      "validate" : "min[0]",
      "behaviour": [
        {
          "condition": "item2 == '1'",
          "type": "conditional_validation",
          "value": {
            "validate":"required,custom[integer],min[1]",
            "message":"test message"
          }
        }
      ]
    }

Computed validation

Parameters included in the validation rules can be computed from an expression as per the example below:

    {
      "validate": [{
        "rule":"max",
        "param": {
            "type": "computed",
            "expression": "item1*3"
          }
      }],
      "dataType": "number",
      "name": "item2"
    }

Warnings

Warnings differ from validations in that they won't prevent the form from being submitted. Warnings can be configured as per the example below:

    {
        "dataType": "number",
        "name": "survivalRate",
        "validate": "required",
        "defaultValue":"",
        "warning":{
            "numericality": {
                "greaterThan":0,
                "message": "Are you sure no plants survived?"
            }
        }
    }

Warnings are currently evaluated using the https://validatejs.org/ library and hence the syntax is very different from validations.