Configure Document Type Field Validators - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 12. There's an updated version available that covers our most recent release.

12-06-2019

Configure Document Type Field Validators

Introduction

Goal

Configure additional field validators in a document type.

Background

Bloomreach Experience Manager provides a number of out-of-the-box field validators that can be used in document 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 configure them in a document type.

If the out-of-the-box validators are not sufficient for your use case, you can create a custom field validator.

Available 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:frontend/cms/cms-validators.

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: &gt; &lt; etc.
email Validate if value is an e-mail address using a regular expression:
^[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$

Required Validator

There is also a built-in required validator. Contrary to the validators listed above, it is not configured in the repository but rather implemented directly in the document editor. The required validator is automatically added to a field by the document type editor when the Required checkbox is checked for that field. 'Required' in this context means the field should have at least one instance.

When setting the required validator, its validation is delegated to the following out-of-the-box validators. Which validator is used depends on the field type:

Name Description
non-empty

Validates that a String value is not empty.

If the type of the value is the builtin "Html" type, the html validator is used to verify this. Such a field therefore does not require the html validator to be declared separately.

html

Validator for HTML values. Verifies that the value is not "visually empty" (e.g. only some spaces, only a single <br> or empty <p> tag, etc.). Use this validator when a customized "Html" type is used.

The builtin "Html" type is checked by the non-empty validator and does not require special treatment.

references Validator for Link fields. Checks if the value is null, empty, or points to the default "empty" node (the JCR root node).
resource-required

Validator for fields that are a (subtype of) hippo:resource. Verifies that a resource has been uploaded.

Note: the document type editor automatically adds this validator to Resource fields with the Required checkbox checked.

image-references Validator for checking mandatory links to images. It checks the link's reference (a node identifier) for not being set at all or being set to the JCR root node or the node /content/gallery.
It should not be combined with the required validator.

Configure Field Validators in a Document Type

  1. Log in to the Console.
  2. Browse to the relevant document type under /hippo:namespaces, for example /hippo:namespaces/myproject/mydocumenttype.
  3. Browse to the document type's node type definition, for example /hippo:namespaces/myproject/mydocumenttype/hipposysedit:nodetype/hipposysedit:nodetype.
  4. Select the child node representing the relevant field, for example /hippo:namespaces/myproject/mydocumenttype/hipposysedit:nodetype/hipposysedit:nodetype/email.
  5. Add the name(s) of the desired validator(s) (see table above) to the multi-valued String property hipposysedit:validators, for 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: [non-empty, required, email]
    
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?