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.
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.
The following example creates a set of four radio buttons with description. The second button will be selected when the UI is first presented.
<field type="radio" variable="radioSelection">
<description txt="This is a description for radio buttons" id="description.radio"/>
<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" />
Beginning from IzPack 5 you can also make single choice elements visible or unvisible depending on conditions: