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.

Multivalue field properties

Simple multivalue field configuration.

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

Node name

Value

 form


 tabs


 tabMain


 fields


 selectCategories


 field


 identifierToPathConverter


 class

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

 class

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

 targetWorkspace

category

 appName

categories

 class

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

 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?

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.

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
Node nameValue

 form


 tabs


 tabText


 fields


 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.  

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
Node nameValue

 form


 tabs


 tabText


 fields


 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
  • No labels

10 Comments

  1. Can we have 'description' property for the fields under 'Multivalue containing a composite field'. Have added description property for the fields. But i don't see the description coming in dialog.
    Please let us know whether this feature is available or not?
    Thank you.

    1. Hi Karthik, your configuration is not the problem here. It's a known issue. There's no UI real estate to show help icons inside the composite field. 

      MGNLUI-3364 - Getting issue details... STATUS

      Description works on the multivalue field, however. Try to be creative with the message, addressing how users should fill the nested fields.

      1. Hi Antti Hietala, Really appreciate for clarification

        Trying to implement your suggestion, now I got another issue. 

        Not able to achieve 'assign Multi line value to a key in properties file'. Tried adding '\n\' at the end of each line. But description text(in the dialog) is just getting appended in the same line instead of coming in new line and also the description is getting limited to very few lines(remaining part of text missed) 




        1. Multiline values don't work in a .properties file, as you discovered, but you can add HTML tags in the help string to break it up.

          myapp.tab.events.description=This help text was applied to the Multivalue field. <br><br> Titles <br> - Add fun events only! <br> - Keep the titles short <br><br> Dates <br> - Some events occur on a <b>different</b> date every year, like Chinese New Year. <br> - Some events occur on the <b>same</b> date every year, like Xmas. <br>- Use date format
          1. It's working !

            Thank you.

  2. Hi there,

    Regarding Alignment of fields(improvisation of look and feel) in a dialog having "Multivalue containing a composite field" .

    From the image in this page, as we are having horizontal layout composite field of 2 fields , dialog is readable easily and very clear.

    But we are using composite field of 10 -15 fields in multifield and if we use horizontal layout for more than 3-4 fields of composite field 'look and feel' is not so appealing for the users and same in case of vertical layout.

    Is there any way we can improvise the look and feel of mentioned scenario ? Could you please provide any suggestions?

    1. we are using composite field of 10 -15 fields

      That sounds like a very complex item. Managing such items in a multivalue field is going to be challenging. Too much going on in the screen, you run out of form real estate.

      Some recommendations:

      • Set wide: true in the dialog definition to get more horizontal space. This probably won't help much with 15 fields. 
      • Stop managing complex items in a composite field. Move them to a dedicated app. Let's say you have an Event field like in our example. Over time, more properties get added to the event: Title, Date, Location, Genre, Organizer, Price, Photos and so on. Consider creating a dedicated Events app. Put all those properties into a vertical form like in our Tours example. The multivalue field now simplifies to just a list of Link fields pointing to items in the Events app.
      • If the fields inside your composite are simple text and numbers maybe you could use a spreadsheet. I believe Vaadin provides a spreadsheet field. You would need to develop a custom field for that.
  3. HI Antti Hietala : Thanks for your comments.

    I mentioned 'dialog' in previous comment, but actually the form we are using is in content App itself where we have composite field of fields displaying in vertical layout as you mentioned.

    Now we are having one more question . Currently we can have single composite field in multivalue field.  Is it possible to have two or more composite fields in Multivaue field? Is this feature can be achieved? Please provide your suggestions.


    1. You cannot have multiple composite fields directly under a multivalue field. But you can nest them inside the single composite you already have.

      Pseudocode:

      multivalue
        composite1
          composite2
          composite3
          composite4
          etc.

      Magnolia Support can provide you with a concrete YAML example if you are an enterprise client. I don't think we have such a complex example in documentation. 

      1. multivalue
          composite1
            composite2
            composite3
            composite4

        We have implemented this scenario to get better look and feel.

        Thanks for you valid suggestion!