XForms/Selecting from Model

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Motivation[edit | edit source]

You want to store lists in the model, not in the user interface. This allows a list to be used many places in a form and also enables lists to be read from external files (see the next example).

Screen Image[edit | edit source]

Execute Sample XForms Application[edit | edit source]

Load XForms Application

Sample Program[edit | edit source]

This example shows how to use the XForms itemset element to get data from the selection list directly from the model. Note that itemset is very similar to the group command in syntax: the outer loop tells you where to get your data and the inner loop binds a data element to a form value or item.

<html xmlns="http://www.w3.org/1999/xhtml" 
        <title>Getting Selection List Data From the XForms Model</title>
        <style type="text/css"><![CDATA[
            body {font-family: Helvetica, Verdanan, sans-serif;}

            <!-- this instance holds the data you send to the server on save -->
            <xf:instance id="my-item" xmlns="">
                    <!-- the default color is red -->

            <!-- this instance holds the code tables used for all selection lists -->
            <xf:instance id="code-tables" xmlns="">
        <h1>Getting Selection List Data From the XForms Model</h1>
        <xf:select ref="ItemColorCode" appearance="full">
                <xf:label ref="label"/>
                <xf:value ref="value"/>
        <br/> Output: <xf:output ref="ItemColorCode"/>

Discussion[edit | edit source]

This is a much more flexible way to manage lists. The instance document may be fetched dynamically from a remote database and the form does not need to be updated when lists change.

Next Page: Selecting from File | Previous Page: Select1 Multi-Column
Home: XForms