Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Javadoc resource link
rangeHigherVersion5.6
classNameinfo.magnolia.ui.form.field.definition.MultiValueFieldDefinition
renderTypeasynchronous
 renders multiple fields that allow the user to either enter multiple values such as items in a shopping list or select multiple items such as categories for tagging content. The multivalue field saves the entered values as a LinkedList<T> collection by default. You can save them in a different way by using a multivalue property transformer.

class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition

The multivalue field is commonly used to select targets inside Magnolia, for example categories for a page.

Table of Contents

Multivalue field properties

Simple multivalue field configuration.

Localtab Group
Localtab
activetrue
titleYAML file
Code Block
languagejs
form:
  tabs:
    - name: tabMain
      label: Categories
      fields:
        - name: selectCategories
          class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
          label: Select category
          field:
            name: linkField
            class: info.magnolia.ui.form.field.definition.LinkFieldDefinition
            targetWorkspace: category
            appName: categories
            identifierToPathConverter:
              class: info.magnolia.ui.form.field.converter.BaseIdentifierToPathConverter
Localtab
titleJCR node
Advanced Tables - Table Plus
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse

Node name

Value

Mgnl n
form


Mgnl n
tabs


Mgnl n
tabMain


Mgnl n
fields


Mgnl n
selectCategories


Mgnl n
field


Mgnl n
identifierToPathConverter


Mgnl p
class

info.magnolia.ui.form.field.converter.BaseIdentifierToPathConverter

Mgnl p
class

info.magnolia.ui.form.field.definition.LinkFieldDefinition

Mgnl p
targetWorkspace

category

Mgnl p
appName

categories

Mgnl p
class

info.magnolia.ui.form.field.definition.MultiValueFieldDefinition

Mgnl p
label

Select category



You can use only the nametypelabeldescription and styleName common field properties  and the following properties in a multivalue field definition:

Properties

<field name>

required

Name of field

field

required

Parent node for the nested child field. Must be named "field".

class

required

Child field definition class.

<other properties>

required/optional*

Any other nodes and properties supported by the child field definition class. *Any required properties must be added.

buttonSelectAddLabel

optional, default is Add

Button label for adding more fields.

buttonSelectNewLabel

optional, default is Select new...

Button label for selecting an item.

buttonSelectOtherLabel

optional, default is Select another...

Button label for selecting a different item.

transformerClass

optional, default is info.magnolia.ui.form.field.transformer.multi.MultiValueTransformer

Property transformer class. Defines how the values are stored in the repository.

See also Which transformer should I use?

Info
titleBest practice
Excerpt

Use DelegatingMultiValueTransformer when nesting more than two levels of fields. The other multivalue transformers can only handle two levels max.

Multivalue containing a single field

Here is an example of a multivalue field that contains a single text field. The parent shopping list is the multivalue field, list items are text fields.

In configuration, define the parent multivalue field first, then add a field node, and define the child field's properties under it.

Localtab Group
Localtab
activetrue
titleYAML file
Code Block
languagejs
form:
  tabs:
    - name: tabMain
      label: Main
      fields:
        - name: shoppingList
          class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
          label: Shopping list
          field:
            class: info.magnolia.ui.form.field.definition.TextFieldDefinition
            label: Title
Localtab
titleJCR node
Advanced Tables - Table Plus
heading0
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
form


Mgnl n
tabs


Mgnl n
tabText


Mgnl n
fields


Mgnl n
shoppingList


Mgnl n
field


Mgnl p
class

info.magnolia.ui.form.field.definition.TextFieldDefinition

Mgnl p
label

Title

Mgnl p
class

info.magnolia.ui.form.field.definition.MultiValueFieldDefinition

Mgnl p
label

Shopping list

Multivalue containing a composite field

Here is an example event list. The parent list is a multivalue field. Each event is a composite field that consists of a text field and a date field.

Note how the NoOpCompositeTransformer is used to prevent the composite field from saving the field values. The NoOpCompositeTransformer hands the responsibility of saving values to the multivalue parent. The default transformer for the multivalue field is the MultiValueTransformer. However, here we cannot use it because it would store the child values in one multivalue property that looks like a comma separated list. That single property is bound to a single type. It cannot handle two different types of values: strings and dates. The solution is to use the MultiValueSubChildrenNodePropertiesTransformer which stores each value in a separate property, allowing them to be of different types.  

Localtab Group
Localtab
activetrue
titleYAML file
Code Block
languagejs
linenumberstrue
form:
  tabs:
    - name: tabText
      label: Multivalue composite
      fields:
        - name: events
          class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
          label: Events
          transformerClass: info.magnolia.ui.form.field.transformer.multi.MultiValueSubChildrenNodePropertiesTransformer
          field:
            name: compositeField
            class: info.magnolia.ui.form.field.definition.CompositeFieldDefinition
            transformerClass: info.magnolia.ui.form.field.transformer.composite.NoOpCompositeTransformer
            fields:
              - name: title
                class: info.magnolia.ui.form.field.definition.TextFieldDefinition
                label: Title
              - name: date
                class: info.magnolia.ui.form.field.definition.DateFieldDefinition
                label: Date
Localtab
titleJCR node
Advanced Tables - Table Plus
heading0
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
form


Mgnl n
tabs


Mgnl n
tabText


Mgnl n
fields


Mgnl n
events


Mgnl n
field


Mgnl n
fields


Mgnl n
title


Mgnl p
class

info.magnolia.ui.form.field.definition.TextFieldDefinition

Mgnl p
label

Title

Mgnl n
date


Mgnl p
class

info.magnolia.ui.form.field.definition.DateFieldDefinition

Mgnl p
label

Date

Mgnl p
class

info.magnolia.ui.form.field.definition.CompositeFieldDefinition

Mgnl p
transformerClass

info.magnolia.ui.form.field.transformer.composite.NoOpCompositeTransformer

Mgnl p
class

info.magnolia.ui.form.field.definition.MultiValueFieldDefinition

Mgnl p
label

Events

Mgnl p
transformerClass

info.magnolia.ui.form.field.transformer.multi.MultiValueSubChildrenNodePropertiesTransformer