Radiobutton Input Field

Description

The radio buttons are useful when the user needs to select a specific option out of a pre-defined list of choices. This field offers an arbitrary number of mutually exclusive buttons, each with its own label. The placement of the buttons and labels is different form other fields. First, the button is placed to the left and the label text to the right. Second, the buttons are not lined up all the way to the left as other labels are but they are indented from that location. As with other fields, the description is placed above the list of radio buttons and uses the entire available layout width. To specify a set of radio buttons create a <field> tag and use the type attribute with a value of radio. The txt and id attributes are not supported here. As with all other input fields, the variable attribute specifies that variable that should be replaced with the user selection.

Data

The data consists of two items, a description and the spec. The <spec> tag has no attributes, instead the specification details are entered as data within the <spec> tag. The <spec> data consists of one or more <choice> tags. One <choice> tag is required for each radio button. The <choice> tag accepts the usual txt and id attributes, which are used to specify the label text. In addition the following attributes are supported:

value - required

The value attribute is used to specify which value to insert if this associated radio button is selected. In other words, the label text has nothing to do with the value that is actually substituted for the variable. For this reason there is never an issue if multiple languages are used, the value is always the same for a given selection.

set - optional

The set attribute accepts the values true and false. Since the attribute is optional it can also be omitted, which is interpreted as false. If a value oftrue is used, the associated radio button will be selected when the UI is first presented. Obviously, only one of the buttons in a set should be set to true.

Example

The following example creates a set of four radio buttons with description. The second button will be selected when the UI is first presented.

1 2 3 4 5 6 7 8 9 <field type="radio" variable="radioSelection"> <description txt="This is a description for radio buttons" id="description.radio"/> <spec> <choice txt="the first choice" id="radio.label.1" value="1 selected" /> <choice txt="the second choice" id="radio.label.2" value="2 selected" set="true" /> <choice txt="the third choice" id="radio.label.3" value="3 selected" /> <choice txt="the fourth choice" id="radio.label.4" value="4 selected" /> </spec> </field>

Beginning from IzPack 5 you can also make single choice elements visible or unvisible depending on conditions:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <panel id="panel.dboperation" summaryKey="key.dboperation.title"> <field type="title" txt="Database operation selection" id="text.dboperation.title" /> <field type="staticText" align="left" txt="Choose the preferred database action:" id="text.dboperation.description" /> <field type="space" /> <field type="radio" variable="db.operation" summaryKey="key.dboperation"> <spec> <choice txt="Build instance as administrator" value="create_instance" id="text.dboperation.create_instance" conditionid="Install"/> <choice txt="Rebuild instance as administrator" value="recreate_instance" id="text.dboperation.recreate_instance" conditionid="Install"/> <choice txt="Build structure as existing user" value="create_structure" id="text.dboperation.create_structure" conditionid="Install"/> <choice txt="Rebuild structure as existing user" value="recreate_structure" id="text.dboperation.recreate_structure" conditionid="Install"/> <choice txt="Don't touch, already manually installed" value="create_none" id="text.dboperation.create_none" conditionid="Install"/> <choice txt="Update existing instance as administrator" value="update_instance" id="text.dboperation.update" conditionid="Update"/> <choice txt="Update existing structure as existing user" value="update_structure" id="text.dboperation.update" conditionid="Update"/> <choice txt="Don't touch, already manually updated" value="update_none" id="text.dboperation.update_none" conditionid="Update"/> <choice txt="Drop instance as administrator" value="drop_instance" id="text.dboperation.drop_instance" conditionid="Uninstall"/> <choice txt="Drop structure as existing user" value="drop_structure" id="text.dboperation.drop_structure" conditionid="Uninstall"/> <choice txt="Don't touch, drop manually later" value="drop_none" id="text.dboperation.drop_none" conditionid="Uninstall"/> </spec> </field> </panel>