Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: MOTION-157

...

Simple validator definition:

title
Localtab Group
Localtab
activetrue
titleYAML file
Code Block
languagejs
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
JCR node
Advanced Tables - Table Plus
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
form

Mgnl n
tabs

Mgnl n
tabUser

Mgnl n
fields

Mgnl n
emailAddress

Mgnl n
validators

Mgnl n
email

Mgnl p
class

info.magnolia.ui.form.validator.definition.EmailValidatorDefinition

Mgnl p
errorMessage

Enter a valid email address

Mgnl p
fieldType

text

Mgnl p
label

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
classNameinfo.magnolia.ui.form.validator.factory.FieldValidatorFactory
renderTypeasynchronous
. 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).

...

Zip code
Code Block
languagejs
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
titleJCR node
Localtab
titleJCR node
Advanced Tables - Table Plus
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
form

Mgnl n
tabs

Mgnl n
tabUser

Mgnl n
fields

Mgnl n
zipCode

Mgnl n
validators

Mgnl n
zip

Mgnl p
class

info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition

Mgnl p
errorMessage

Enter a valid U.S. ZIP code using the format 12345 or 12345-1234

Mgnl p
pattern

^\d{5}(-\d{4})?$

Mgnl p
fieldType

text

Mgnl p
label

Custom validators

To write your own validator class:

...