Configure Document Type Validators
Introduction
Goal
Configure additional validators in a document type.
Background
Bloomreach Experience Manager provides a number of out-of-the-box validators that can be used in content types. Most of these validators cannot be added using the document type editor and must be manually configured using the Console.
This page describes the available validators and explains how to add them to a content type. Validators can have field scope, compound scope, or document scope. All validators are compatible with both the document editor in the Content application and the visual editor in the Experience manager.
If the out-of-the-box validators are not sufficient for your use case, you can create a custom validator.
Available Validators
Out-of-the-Box Validators
The table below lists all available out-of-the-box validators. Their default configurations can be found in the repository at /hippo:configuration/hippo:modules/validation/hippo:moduleconfig.
Name | Description |
---|---|
escaped | Validates that a String value is HTML-escaped using a regular expression:
/.*[<>&\"'].*/In short, the characters <>&"' are not allowed and should be replaced with HTML entities like: > < etc. |
Validates that a value is an valid e-mail address using a regular expression:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$ |
|
required |
Validates that the value of field is present. The required validator is automatically added to a field by the document type editor when the Required checkbox is checked for that field. This validator uses several other validators internally that perform the actual validation based on the type of the validated field. After the label of a required field an asterisk * is added to mark the field as such. |
non-empty | Validates that a String field has a non-empty value. Only useful in combination with optional fields (see Document Type Editor for details on optional fields). Otherwise, use the required validator. |
non-empty-html | Validates that an HTML field has a non-empty value. This means that the HTML content must be visible for the user. Empty p, span or div tags for example are considered to be 'empty'. Useful in combination with optional fields (see Document Type Editor for details on optional fields). Otherwise, use the required validator. |
references | Validates that a Link field has a non-empty value. Only useful in combination with optional fields (see Document Type Editor for details on optional fields). Otherwise, use the required validator. |
image-references |
Validates that a Image Link field has a non-empty value. Only useful in combination with optional fields (see Document Type Editor for details on optional fields). Otherwise, use the required validator. |
url | Validates that a String value is a valid URL by checking the scheme, authority, path, query, and fragment in turn. Note: available since v14.5. |
Other Available Validators
The following validators are available as Java class but must be manually configured in the implementation project at /hippo:configuration/hippo:modules/validation/hippo:moduleconfig. See 'Configure a Validator' in Create a Custom Validator.
Sequential Dates Validator
Document or compound-scoped validator to check if dates in two or more date fields are in sequence.
During validation, all dates are read off the to-be-validated node, deeper nesting is not supported by this validator. The date property names (and order) must be specified with a multivalued String property datePropertyNames property on the validator's configuration node (project-specific). Missing or empty date properties are ignored, those should be addressed through the 'required' validator.
Example from the 'Events' feature in the Essentials library:
/hippo:configuration/hippo:modules/validation/hippo:moduleconfig/myproject-events-sequential-dates: jcr:primaryType: hipposys:moduleconfig datePropertyNames: ['myproject:date', 'myproject:enddate'] hipposys:className: org.onehippo.cms.services.validation.validator.SequentialDatesValidator
Add Validators to Content Types
Add Validators to a Field in a Document Type
- Log in to the Console.
- Browse to the relevant document type under /hippo:namespaces, for example /hippo:namespaces/myproject/mydocumenttype.
- Browse to the document type's node type definition, for example /hippo:namespaces/myproject/mydocumenttype/hipposysedit:nodetype/hipposysedit:nodetype.
- Select the child node representing the relevant field, for example /hippo:namespaces/myproject/mydocumenttype/hipposysedit:nodetype/hipposysedit:nodetype/email.
- Add the name(s) of the desired validator(s) (see table above) to the multi-valued String property hipposysedit:validators. Make sure each validator supports the relevant scope (field or compound).
Example:/hippo:namespaces/myproject/mydocumenttype/hipposysedit:nodetype/hipposysedit:nodetype/email: jcr:primaryType: hipposysedit:field hipposysedit:mandatory: false hipposysedit:multiple: false hipposysedit:ordered: false hipposysedit:path: myproject:email hipposysedit:primary: false hipposysedit:type: String hipposysedit:validators: [required, email]
Add Validators to a Document or Compound Type
- Log in to the Console.
- Browse to the relevant document or compound type under /hippo:namespaces, for example /hippo:namespaces/myproject/eventsdocument.
- Browse to the document or compound type's node type definition, for example /hippo:namespaces/myproject/eventsdocument/hipposysedit:nodetype/hipposysedit:nodetype.
- Add the name(s) of the desired validator(s) (see table above) to the multi-valued String property hipposysedit:validators. Make sure each validator supports the relevant scope (compound or document).
Example from the 'Events' feature in the Essentials library:/hippo:namespaces/myproject/eventsdocument/hipposysedit:nodetype/hipposysedit:nodetype: jcr:primaryType: hipposysedit:nodetype jcr:mixinTypes: ['hipposysedit:remodel', 'mix:referenceable'] hipposysedit:node: true hipposysedit:supertype: ['myproject:basedocument', 'hippostd:relaxed', 'hippotranslation:translated'] hipposysedit:uri: http://www.myproject.com/myproject/nt/1.0 hipposysedit:validators: [myproject-events-sequential-dates]