SchemaToCode
NGX-SCHEMA-TO-CODE
Version 1.1.1

From version 1.1.0 following changes has been done to validations

  • By default all input fields / properties will have required validation, if it is not define inside property.
  • "__requiredAllExcept": [ ] metadata added to entity level, this is for opt-out option for required validation, you can add property names to string array to exclude from required validation.

    Example:

    {
      "employee": {
        "__requiredAllExcept": ["lastName", "address.area"], // These properties will not have required validation.
        "firstName": {
          "minLength": 5,
          "maxLength": 30
        },
        "lastName": {},
        "address": {
          "dataType": "group",
          "displayName": "Current Address",
          "inputType": "group",
          "properties": {
            "area": {
              "maxLength": 50
            },
            "city": {}
          }
        }
      }
    }
    
  • "__required": [ ] metadata added to entity level, this is opt-in option for validation you need add all property names whome required validation need to be apply, other properties will be exclue from required validation.

    Example: In above example just replace "__requiredAllExcept" whole line with following will be yield the same result.

    "__required": ["firstName", "address.city"],     // These properties will have required validation.


    NOTE: You can use either '__requiredAllExcept' or '__required', you cannot be use both for same entity.

  • If required validation define inside individual property, it will take predence, regarless of any global settings.
  • Now you can define all validation directly at root level in the property, no need to put them in inside 'validation' metadata.

You can add validation to any input type, including array. For array you can only add required validation, it means at least one item is required.


Available validations:

  • "required": true
  • "minLength": 5
  • "maxLength": 30
  • "pattern": "^[A-Z]{5}[0-9]{4}[A-Z]{1}$"
  • "min": 10000
  • "max": 75000
  • "email": true

New clean way from version 1.1.0

"firstName": {
  "minLength": 5,
  "maxLength": 30
  "hint": "First  Name should be between 5 to 30 characters long" // It will show hint for input
}

Old way before version 1.1.0 to define validations

"firstName": {
  "dataType": "string",  
  "inputType": "text",
  "validation": {
    "required": true,
    "minLength": 5,
    "maxLength": 30,
  }
  "hint": "First  Name should be between 5 to 30 characters long" // It will show hint for input
}

Note: When you use inputType 'email' the system will be add email and pattern validation "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", you need not required to add them explicitly.

Related Topics:

Text, Textarea, Number, String, Email, Group, Array,