Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.

Page tree
Skip to end of metadata
Go to start of metadata

MultiValueFieldDefinition  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.

Configuration

When configuring a multivalue field, create a field node and define the child field's properties under it.

Node name 

 <multivalue field>

 

 field

 

 class

<child field definition class>

 <other child field properties>

 

 class

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

Common field properties applicable to the multivalue field are nametypelabeldescription and styleName.

You can additionally define the following properties.

PropertyDescriptionDefault value
buttonSelectAddLabelButton label for adding more fields. Retrieved from a message bundle. Optional.

field.link.select.new

Displayed as: Add

buttonSelectNewLabelButton label for selecting an item. Retrieved from a message bundle. Optional.

field.link.select.new

Displayed as: Select new...

buttonSelectOtherLabelButton label for selecting a different item. Retrieved from a message bundle. Optional.

field.link.select.another

Displayed as: Select another...

transformerClassProperty transformer class. Defines how the values are stored in the repository. Optional.info.magnolia.ui.form.field.transformer.multi.MultiValueTransformer

Best practice

When nesting multivalue fields, use the delegating transformer classes, DelegatingCompositeFieldTransformer or DelegatingMultiValueFieldTransformer, rather than the other available transformer classes.

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.

Node nameValue

 shoppingList

 

 field

 

 class

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

 label

Title

 class

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

 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.  

Node nameValue

 events

 

 field

 

 fields

 

 title

 

 class

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

 label

Title

 date

 

 class

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

 label

Date

 class

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

 transformerClass

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

 class

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

 label

Events

 transformerClass

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