XForms/Open Selection

MotivationEdit

You want to have a control that suggests a set of values in a drop-down list but also allows a user to type in their own value.

MethodEdit

Just add the attribute selection="open" to your select1 control:

<xf:select1 ref="my-data" selection="open">

Screen ImageEdit

Select1 Control with selection attribute set to be open

Note that although a list of possible countries is listed, the user can type in any country that is not on this list.

XForms ApplicationEdit

Load XForms Application

The following example allows you to select a country code or enter your own country code:


<html
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xf="http://www.w3.org/2002/xforms">
   <head>
      <title>XForms Select1 Control Using Open Selection</title>
      <style type="text/css"><![CDATA[body {font-family: Helvetica, sans-serif;}]]></style>
        <xf:model>
            <xf:instance xmlns="">
                <data>
                    <CountryCode/>
                </data>
            </xf:instance>
        </xf:model>
   </head>
   <body>
      <p>XForms Select1 control using selection="open"</p>
      <xf:select1 ref="CountryCode" selection="open">
            <xf:label>Country:</xf:label>
            <xf:item>
                <xf:label>USA</xf:label>
                <xf:value>usa</xf:value>
            </xf:item>
            <xf:item>
                <xf:label>Canada</xf:label>
                <xf:value>can</xf:value>
            </xf:item>
            <xf:item>
                <xf:label>Japan</xf:label>
                <xf:value>jpn</xf:value>
            </xf:item>
            <xf:item>
                <xf:label>Mexico</xf:label>
                <xf:value>mex</xf:value>
            </xf:item>
            <xf:item>
                <xf:label>Other</xf:label>
                <xf:value>other</xf:value>
            </xf:item>
       </xf:select1>
       <br/>
       Output: <xf:output ref="CountryCode"/>
   </body>
</html>

DiscussionEdit

Very often you want to suggest values to the user to ensure consistency of data entry. The problem is that there are sometimes exceptions to a small list of items and the open selection control allows these exceptions to be entered.

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".


Next Page: Select | Previous Page: Select1 drop list

Home: XForms

Last modified on 24 March 2011, at 18:41