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

SwitchableFieldDefinition  defines a field that displays alternative fields depending on user choice. For example:

  • Switch between a plain text editor and a rich text editor. 

  • Authenticated vs. unauthenticated SMTP settings. When the user selects the authenticated option, ask for username and password.
  • In a shop, switch between separate shipping and billing addresses or using the same address for both..

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

Here is a switchable text editor field. It consists of alternative plain text and rich text fields.

The switchable field is defined like this:

Node nameValue

 editor

 

 options

 

 plain

 

 label

 Plain

 selected

 true

 value

 plainText

 rich

 

 label

 Rich

 value

 richText

 fields

 

 plainText

 

 class

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

 label

Plain text message

 richText

 

 class

info.magnolia.ui.form.field.definition.RichTextFieldDefinition

 label

Rich text message

 class

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

 label

Message

You can use all common field properties and the following:

PropertyDescription

<switchable field>

Parent switchable field.

options

Options (radio buttons) that allow switching between child fields. You can add more than two options.

<option 1>

First option

label

Label displayed next to the radio button.

selected

If true, the option is selected by default.

value

Name of the child field node that should be displayed when the option is selected.

<option 2>

 

label

 

selected

 

value

 

fields

Child fields that are displayed when the user selects an option.

<child field 1>

Child field name. Must match the option value property.

class

Definition class of the child field. (warning) Basic upload field does not work inside a switchable field.

<child field 2>

 

class

 

class

Definition class of the switchable parent field. Mandatory. Use info.magnolia.ui.form.field.definition.SwitchableFieldDefinition .

layout

Defines the layout of the radio buttons: horizontal or vertical.

transformerClass

Custom property transformer definition. Optional. The default transformer for switchable fields is info.magnolia.ui.form.field.transformer.composite.SwitchableTransformer.

Best practice

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