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 name | Value |
---|---|
confirmContentType |
|
options | |
code | |
label | dialog.form.tabContactMail.contentType.option.code |
selected | false |
value | code |
text | |
page | |
fields | |
code | |
class | info.magnolia.ui.form.definition.BasicTextCodeFieldDefinition |
i18n | true |
language | html |
class | info.magnolia.ui.form.field.definition.SwitchableFieldDefinition |
i18nBaseName | info.magnolia.module.form.messages |
label | dialog.form.tabContactMail.contentType.label |
type | String |
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 name | Value |
---|---|
confirmContentType | text |
confirmContentTypetext | some text |
confirmContentTypelink | 1b106efa-3b4f-41d3-aae6-cf368a9667b9 |
confirmContentTypecode | some code |
Configuration
You can use all common field properties and the following:
Property | Description | Default value |
---|---|---|
options
| Parent node for the selectable options. | |
value | Name of the related field definition This value is saved to the repository when this option is the last displayed/selected. Mandatory. | |
iconSrc | Displays an image next to the option. The value is a path to the image. Optional. | |
label | The option label displayed to the user. Optional. | |
selected | Pre-selects the option. Optional. | false |
fields
| Parent node containing the single field that composed the switchable field. | |
field1 | Parent node of one field composing the composite field. Field name should match the option value | |
class | Class definition of the field1 | |
... | Continue with field1 definition | |
... | Add any number of field definition that should composed the composite field. | |
class | SwitchableFieldDefinition class name. Mandatory. | |
selectionType | Display the options as radio button or as a selection list. Optional. | radio |
| Custom definition. Optional. |
|
layout | Define the select option layout in case of selectionType=radio . Layout of the radio button could be vertical or horizontal . Optional. | horizontal |