...
Simple validator definition:
Localtab Group |
---|
Localtab |
---|
|
Code Block |
---|
|
form:
tabs:
- name: tabUser
label: User info
fields:
- name: emailAddress
fieldType: text
label: Email
validators:
- name: email
class: info.magnolia.ui.form.validator.definition.EmailValidatorDefinition
errorMessage: Enter a valid email address Localtab | title | JCR node | Advanced Tables - Table Plus |
---|
enableHeadingAttributes | false |
---|
enableSorting | false |
---|
class | m5-configuration-tree |
---|
enableHighlighting | false |
---|
|
Node name | Value |
---|
| | | | | | | | info.magnolia.ui.form.validator.definition.EmailValidatorDefinition |
| Enter a valid email address |
| text |
| Email |
Properties:
<field name> | Name of field. |
validators
| required Contains the validator definition. |
<validator name>
| required Arbitrary node name. Use a name that describes the validator type. |
class
| required Validator definition class. Use the fully-qualified class name. |
factoryClass
| optional Fully qualified name of the Java class that creates the validator. The class must implement Javadoc resource link |
---|
className | info.magnolia.ui.form.validator.factory.FieldValidatorFactory |
---|
renderType | asynchronous |
---|
|
. Validator definitions specify a default factory class, meaning that unless you want to use a custom implementation you don't need to configure a factory class. |
errorMessage
| optional Text displayed to the user on invalid input. Text string or message bundle key. |
i18nBasename
| optional Message bundle for localized messages. This property can be set at dialog, form, tab or field level. |
pattern
| required for regex validation Regular expression pattern when using the info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition class |
...
Here is an example of validating a ZIP code (U.S. postal code).
...
Code Block |
---|
|
form:
tabs:
- name: tabUser
label: User info
fields:
- name: zipCode
fieldType: text
label: Zip code
validators:
- name: zip
class: info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition
pattern: ^\d{5}(-\d{4})?$
errorMessage: Enter a valid U.S. ZIP code using the format 12345 or 12345-1234 Localtab |
---|
|
|
Localtab |
---|
|
Advanced Tables - Table Plus |
---|
enableHeadingAttributes | false |
---|
enableSorting | false |
---|
class | m5-configuration-tree |
---|
enableHighlighting | false |
---|
|
Node name | Value |
---|
| | | | | | | | info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition |
| Enter a valid U.S. ZIP code using the format 12345 or 12345-1234 |
| ^\d{5}(-\d{4})?$ |
| text |
| Zip code
Custom validators
To write your own validator class:
...
Info |
---|
icon | false |
---|
title | Best practice |
---|
|
Excerpt |
---|
Define default values for fields or check for null values. This ensures that you can submit the form. For example, if you define an option group field and do not provide a default value, an error will occur when a user submits the form by email. The email processor does not check for null values in the template. It is good practice to check for null values of any variables you call. You can check for null values and provide a default value in a Freemarker script like this: Code Block |
---|
| field: ${field!"value not provided"} |
|
|