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.
Use
DelegatingMultiValueTransformer
when nesting more than two levels of fields. The other multivalue
transformers can only handle a maximum of two levels.
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, and the 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.
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
NoOpCompositeTransformer
is used to prevent the composite field from saving the field values.
NoOpCompositeTransformer hands the responsibility of saving values to
the multivalue parent. The default transformer for the multivalue field
is
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
MultiValueSubChildrenNodePropertiesTransformer,
which stores each value in a separate property, allowing them to be of
different types.