Input Validation

The user input provided in the form fields in Object card can be validated.

Validate Input Fields

Here is an example how form field user input can be validated:

{
	"id": "comment",
	"label": "Comment",
	"type": "TextArea",
	"placeholder": "Comment",
	"validations": [
		{
			"required": true,
			"message": "Field is required. Please enter a text.",
			"type": "Error"
		}
	]
}

For each form input field can be added one or more validations. Each validation contains:

The currently available validation functions are:

Here is an example of adding multiple validation functions in a single validation:

"validations": [
	{
		"minLength": 10,
		"maxLength": 200,
		"message": "Your comment should be between 10 and 200 characters.",
		"type": "Warning"
	}
]

Here is an example of adding multiple validations to a single input:

"validations": [
	{
		"required": true
	},
	{
		"minLength": 10,
		"maxLength": 200,
		"message": "Your comment should be between 10 and 200 characters.",
		"type": "Warning"
	}
]

Here is an example of adding a regular expression pattern to a single input:

"validations": [
	{
		"required": true
	},
	{
		"pattern": "^\\w+[\\w-+\\.]*\\@\\w+([-\\.]\\w+)*\\.[a-zA-Z]{2,}$",
		"message": "You should enter a valid e-mail."
	}
]
Try it Out

"messages" Model

For each card a "messages" model is created. It contains all validation messages. Here is the "messages" model structure:

Here is an example how the "messages" model can be used to disable the "Submit" button if there are any validation errors:

"footer": {
	"actionsStrip": [
		{
			"text": "Submit",
			"buttonType": "Accept",
			"actions": [
				{
					"enabled": "{= !${messages>/hasErrors}}",
					"type": "Submit"
				}
			]
		}
	]
}
Try it Out