Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Motivation

You want an input control that allows a user to select one and only one item from a list of possible items. You have enough room on the form to display all the possible values. You would also like what the user sees and what is placed in the instance to be different.

Method

Any time you would like the user to make a single selection from a list of possible options you can use the XForms select1 control. There are two variations of this, one to display all the values (also known as a radio-button) and one that presents a drop-down list and thus takes up less screen area.

Each item on the list of possible choices must have an item and within that it must have a value and an optional label. The value is the string that will be inserted into the data element that is referenced using the ref property. The ref property points to a data element in your model.

Select1 Radio Buttons

Note that the lower-case value will be displayed under the select1 control to show you how the select1 control is changing the model. Only the labels are shown to the user.

Example Program

In the example below, the instance variable MyCode inside MyModel will be set to the value selected by the radio buttons control.

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms">

XForms Radio Button Usng Select1 appearance="full"

xmlns="">

XForms Radio Button Usng Select1 appearance="full"

ref="ColorCode" appearance="full" >

Red
red

Orange
orange

Yellow
yellow

Green
green

Blue
blue

Output: ref="ColorCode"/>

Testing

You should see all the possible values when you use a full appearance. Each time you click on one of the radio buttons, the value of MyCode in the model will be updated and the output should automatically be updated. Note that the value is displayed (in lowercase), not the label.

Changing the Orientation to Horizontal

You can change the radio button to use a horizontal layout by applying float:left style to all the item elements.

Horizontal Radio Button (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)

In your CSS do the following:

.horiz xf|item {
float: left;
}

In your body wrap all of the xf:item elements in a div with a class="horiz"

ref="my-element" appearance="full">
Color:
class="horiz">

Red
red

Green
green

Red
blue

Discussion

You can always change a radio button to a drop down list by just removing the appearance="full" attribute from the select1 element.

You can also use an XPath expression to display labels and values from the model using the xf:itemset element.

ref="my-element">
nodeset="instance('codes')/data/item">
ref="label"/>
ref="value"/>

See the other examples for examples of this.

Acknowledgments

The question about horizontal layout was posted on the mozilla.dev.tech.xforms mailing list in April of 2008 and the solution was provided by Aaron from IBM.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
Values are typically stored in a database and use to compare to items together. Since values are frequently passed as arguments in a URL in a REST interface the convention is to only use lowercase letters and dashs. Do not put spaces, slashes and other characters in values if you are using REST inte
CC BY-SA 4.0
One challenge of using this control is to let the user know they can enter an exception. You may have to add instructional text on the form such as "type value in this field if it does not appear on this list".
CC BY-SA 4.0
Note that in this program we use appearance="full" attribute. ## XForms Application [Load XForms Application]( Note that as you select multiple items a space-delimited list of items appears in the output. This is a good example of why you do not want to put any spaces in a selection item **value** t
CC BY-SA 4.0
Make sure to put the page into edit mode if you want to copy and paste the code. This is because Wiki software replaces the ampersand-lt-semicolon with a "&". xmlns=" xmlns:xf=" xmlns:xs=" xmlns:ev=" Select County type="text/css"> @namespace xf url(" body { font-family: Helvetica, sans-serif; font-s
CC BY-SA 4.0
XForms, Select1 Multi-Column
CC BY-SA 4.0
xmlns=" xmlns:xf=" Getting Selection List Data From the XForms Model type="text/css"> body {font-family: Helvetica, Verdanan, sans-serif;} ]]> id="my-item" xmlns=""> red id="code-tables" xmlns=""> ItemColorCode Red red Orange orange Yellow yellow Green green Blue blue Getting Selection List Data Fro