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

SwitchableFieldDefinition renders a complex field that display fields based on selections (select list or radio buttons).

Class: info.magnolia.ui.form.field.definition.SwitchableFieldDefinition

Here is an example coming from the main configuration menu of the form module.
Code is selected:

and if you click on link, the Link field is displayed instead of the Code field:

 

Node nameValue

 confirmContentType

 

      options 
           code 
                labeldialog.form.tabContactMail.contentType.option.code
                selectedfalse
                valuecode
           text 
           page 
      fields 
           code 
                classinfo.magnolia.ui.form.definition.BasicTextCodeFieldDefinition
                i18ntrue
                languagehtml

 class

info.magnolia.ui.form.field.definition.SwitchableFieldDefinition

         i18nBaseNameinfo.magnolia.module.form.messages
         labeldialog.form.tabContactMail.contentType.label
         typeString

 

Storing strategy

By default the transformerClass is set to SwitchableTransformer.

Let's take the previous example and assume that:

  • We enter a value for each field
    • code: 'some code'
    • text: 'some text'
    • link: '1b106efa-3b4f-41d3-aae6-cf368a9667b9'
  • The selected option was text.

Then the following properties are stored in the JCR repository:

Node nameValue
 confirmContentTypetext
 confirmContentTypetextsome text
 confirmContentTypelink1b106efa-3b4f-41d3-aae6-cf368a9667b9
 confirmContentTypecodesome code

Configuration

 You can use all common field properties and the following:

PropertyDescriptionDefault value
options
Parent node for the selectable options. 
   valueName of the related field definition(info).
This value is saved to the repository when this option is the last displayed/selected. Mandatory.
 
   iconSrcDisplays an image next to the option. The value is a path to the image. Optional. 
   labelThe option label displayed to the user. Optional. 
   selectedPre-selects the option. Optional.false
fields
Parent node containing the single field that composed the switchable field. 
   field1Parent node of one field composing the composite field.
Field name should match the option value(info).
 
     classClass definition of the field1 
     ...
Continue with field1 definition 
   ...Add any number of field definition that should composed the composite field. 
classSwitchableFieldDefinition class name. Mandatory. 
selectionTypeDisplay the options as radio button or as a selection list. Optional.radio
transformerClassCustom transformer  definition. Optional.
layoutDefine the select option layout in case of selectionType=radio . Layout of the radio button could be
vertical  or horizontal . Optional.
horizontal

 

 

  • No labels