Field definition

A field is an HTML form element that allows you to perform a task such as enter text, upload an image or select a date.

This field definition is part of the Magnolia 6 UI framework. The fully qualified class name is info.magnolia.ui.field.FieldDefinition.

If you work with the Magnolia 5 UI framework, see Field definition for Magnolia 5 UI instead.

Field examples module

You can download an example light module called field-examples-module . The module contains working field definitions to use out of the box for all fields in this section. Follow the instructions below to preview them in your local Magnolia installation.

  1. Set the content bootstrap folder, pattern, and strategy in the WEB-INF/config/default/magnolia.properties file. For example:

    magnolia.content.bootstrap.dir=/<LIGHT-MODULE-FOLDER-LOCATION>/field-examples-module/bootstrap/data
    magnolia.content.bootstrap.pattern=*.{yaml,xml}
    magnolia.content.bootstrap.createTasks=always
  2. Unzip and copy the fields-examples-module into your light-modules folder.

    Two field examples use the books workspace. Previewing those fields requires completing the Bookshelf app tutorial or cloning the bookshelf repository directly into your light-modules folder.

  3. Start up your Magnolia instance and log in.

  4. You should see three import tasks in the Tasks app. One is for an asset, one to import books, and another for a page. Import all files.

  5. Go to the Pages app and check that the Field examples page is successfully bootstrapped.

  6. Edit the new page and add a new component. This opens a dialog showing all the component types available.

    Add component dialog
  7. After selecting a component type and clicking Next, the respective dialog fields are shown.

    You can change the values, save them, and then edit them again later.

Example definition

To add a field to your form, you need to define a field. Field definition must contain a class or $type property, which tells Magnolia what type of field to render. Set the property value to a fully qualified class name (for class) or field alias (for $type). Depending on the field type, a number of common simple field properties or complex field properties are supported.

firstName:
  label: First name
  $type: textField
  required: true
lastName:
  label: Last name
  $type: textField
  required: true
email:
  label: Email
  $type: textField
  required: true
  validators:
    email:
      $type: emailValidator

Common simple field properties

You can use the following properties with any simple field (all except composite, multi, static and switchable fields).

Property Description

name

required

Name of the field definition item. Derived from the configured node name. Use alphanumeric characters without spaces.

class

required (unless $type is used)

Type of the field definition item. The value must be a fully qualified class name and a subtype of info.magnolia.ui.field.FieldDefinition. See Field types for possible values.

$type

You can use this as a shortcut for class if the definition class is annotated with info.magnolia.ui.field.FieldType. The proper value is defined by the annotation.

Example class annotation
@FieldType("textField")
public class TextFieldDefinition extends ConfiguredFieldDefinition<String> {
...
}

See Field types for possible values.

type

optional

Property type of the field.

A default type is typically hard-coded in each definition class. You only need to add this property if you want to override the default implementation.

In text fields, make sure that type has a value matching the type of data you entered (for example, java.lang.Long for long values) and that converterClass is set accordingly.

Example definition
text:
  $type: textField
  type: java.lang.Long
  converterClass: com.vaadin.data.converter.StringToLongConverter

converterClass

optional

Converts values between the presentation (UI) and model (stored data). The property must extend com.vaadin.data.Converter. Available classes:

  • info.magnolia.ui.editor.converter.JcrNodeToIdentifierConverter

  • info.magnolia.ui.editor.converter.JcrNodeToPathConverter

  • info.magnolia.ui.editor.converter.JcrNodeToWorkspaceAndIdConverter

  • info.magnolia.ui.editor.converter.JcrPathToIdentifierConverter

com.vaadin.data.converter.StringToBigDecimalConverter and com.vaadin.data.converter.StringToDoubleConverter always round the presentation value by default. For non-rounding converters, use the following classes instead:

  • info.magnolia.ui.field.converter.NonRoundingStringToBigDecimalConverter

  • info.magnolia.ui.field.converter.NonRoundingStringToDoubleConverter

conversionErrorMessage

optional, default is translated conversion.message.error key

Message shown when there is an error in the conversion process. The value can be literal or a key of a message bundle.

defaultValue

optional

Pre-filled default value displayed in the field. The value can be overwritten by the user. Use alphanumeric characters.

This is only applied only when creating a new item, not for existing items.

For defaultValue to work, the populate property in info.magnolia.ui.dialog.actions.OpenDialogActionDefinition must be set to false.

description

optional

Help text displayed when the user clicks the help icon. The value can be literal or a key of a message bundle.

factoryClass

optional

Defines the factory class that initializes and builds the Vaadin form field. The default factory class depends on the particular field.

The value must be a fully qualified class name and a subtype of info.magnolia.ui.field.FieldFactory.

fieldBinderClass

optional

Defines the binder class that applies configuration parameters from the field.

i18n

optional, default is false

Enables i18n authoring support, which allows editors to write foreign-language or regionally targeted content. A two-letter language identifier (en, de, fr, etc.) is displayed on controls where i18n is set to true.

label

optional

Field label displayed to editors. The value can be literal or a key of a message bundle.

If you do not provide the property, Magnolia will fall back to a generated i18n key.

If you do not want to have any label, set the property to an empty string such as label: "" in YAML.

readOnly

optional, default is false

Makes the field uneditable.

required

optional, default is false (not relevant for checkbox field)

Makes the field required. When true, an asterisk is displayed next to the field label.

When false, empty values are accepted as valid. For those empty values, any field validators are ignored.

requiredErrorMessage

optional, default is translated validation.message.required key

Error message shown when required is set to true and the user saves an empty field. The value can be literal or a key of a message bundle.

styleName

optional

Additional style information for an editor property definition item applied to the element when the form is rendered. The value can be a CSS class or a list of CSS classes separated by white spaces.

The style name will be rendered as an HTML class name, which can be used in a CSS definition. The class name is added to the field by calling the Vaadin method addStyleName.

The referenced class can be defined in:

validators

optional

List of field validator definition items. Any value must be a subtype of info.magnolia.ui.field.FieldValidatorDefinition.

See Field validators for more information.

Setting role permissions at the level of individual fields is not possible currently.

Common complex field properties

You can use the following properties with any complex field (composite, multi, static and switchable fields).

Property Description

name

required

Name of the field definition item. Derived from the configured node name. Use alphanumeric characters without spaces.

class

required (unless $type is used)

Type of the field definition item. The value must be a fully qualified class name and a subtype of info.magnolia.ui.field.FieldDefinition. See Field types for possible values.

$type

You can use this as a shortcut for class if the definition class is annotated with info.magnolia.ui.field.FieldType. The proper value is defined by the annotation.

Example class annotation
@FieldType("textField")
public class TextFieldDefinition extends ConfiguredFieldDefinition<String> {
...
}

See Field types for possible values.

itemProvider

required, default is

  • JcrPropertyProvider for JcrMultiValueFieldDefinition

  • JcrChildNodeProviderDefinition for JcrMultiFieldDefinition

  • CurrentItemProviderDefinition for StaticFieldViewDefinition

Node with a $type property that specifies the type of data binding for the subnodes in complex fields.

See Item providers for more information.

Do not use JcrMultiValueFieldDefinition with any item provider other than the default JcrPropertyProvider.

description

optional

Help text displayed when the user clicks the help icon. The value can be literal or a key of a message bundle.

i18n

optional, default is false

Enables i18n authoring support, which allows editors to write foreign-language or regionally targeted content. A two-letter language identifier (en, de, fr, etc.) is displayed on controls where i18n is set to true.

label

optional

Field label displayed to editors. The value can be literal or a key of a message bundle.

If you do not provide the property, Magnolia will fall back to a generated i18n key.

If you do not want to have any label, set the property to an empty string such as label: "" in YAML.

styleName

optional

Additional style information for an editor property definition item applied to the element when the form is rendered. The value can be a CSS class or a list of CSS classes separated by white spaces.

The style name will be rendered as an HTML class name, which can be used in a CSS definition. The class name is added to the field by calling the Vaadin method addStyleName.

The referenced class can be defined in:

Field types

$type class

checkBoxField

info.magnolia.ui.field.CheckBoxFieldDefinition

checkBoxGroupField

info.magnolia.ui.field.CheckBoxGroupFieldDefinition

codeField

info.magnolia.ui.field.CodeFieldDefinition

comboBoxField

     jsonComboBoxField

info.magnolia.ui.field.ComboBoxFieldDefinition info.magnolia.rest.ui.field.comboboxfield.JsonComboBoxFieldDefinition

compositeField

     jsonCompositeField

info.magnolia.ui.field.CompositeFieldDefinition info.magnolia.rest.ui.field.JsonCompositeFieldDefinition

dateField

info.magnolia.ui.field.DateFieldDefinition

hiddenField

info.magnolia.ui.field.HiddenFieldDefinition

linkField

     damLinkField
     jsonLinkField
     pageLinkField
     resourceLinkField

info.magnolia.ui.field.LinkFieldDefinition

info.magnolia.dam.app.field.DamLinkFieldDefinition
info.magnolia.rest.ui.field.linkfield.JsonLinkFieldDefinition
info.magnolia.pages.app.field.PageLinkFieldDefinition
info.magnolia.resources.app.field.ResourceLinkFieldDefinition

listSelectField

info.magnolia.ui.field.ListSelectFieldDefinition

multiField

     jcrMultiField
         multiJcrBlock
     jcrMultiValueField
         jcrMultiLinkField
     jsonMultiField

info.magnolia.ui.field.MultiFieldDefinition

info.magnolia.ui.field.JcrMultiFieldDefinition

info.magnolia.editor.block.jcr.MultiJcrBlockDefinition

info.magnolia.ui.field.JcrMultiValueFieldDefinition

info.magnolia.ui.field.JcrMultiLinkFieldDefinition

info.magnolia.rest.ui.field.JsonMultiFieldDefinition

passwordField

info.magnolia.ui.field.PasswordFieldDefinition

radioButtonGroupField

info.magnolia.ui.field.RadioButtonGroupFieldDefinition

richTextField

info.magnolia.ui.field.RichTextFieldDefinition

sliderField

info.magnolia.ui.field.SliderFieldDefinition

staticField

info.magnolia.ui.field.StaticFieldViewDefinition

switchableField

info.magnolia.ui.field.SwitchableFieldDefinition

textField

     slugField

info.magnolia.ui.field.TextFieldDefinition info.magnolia.editor.field.SlugFieldDefinition

tokenField

info.magnolia.ui.field.TokenFieldDefinition

twinColSelectField

info.magnolia.ui.field.TwinColSelectFieldDefinition

Your Magnolia installation may contain more fields depending on the installed modules.
Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules