Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Motivation

There are three core concepts that you will learn in building XForms applications:

  • The model is a tree of data elements
  • The presentation is a tree of data elements
  • To build your form, these two trees need to be wired together - this is called "binding"

Many of the exercises in this cookbook give examples of this binding. This process is a small example of how this can work. In practice there are many ways to bind the user interface to the model.

Screen Image

The screen image is similar to input programs from a prior example. This example has two input fields for a person's first and last name and two output controls.

Sample Program

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Your Title Here

xmlns="">

id="PersonGivenName" nodeset="/data/PersonGivenName"/>
id="PersonSurName" nodeset="/data/PersonSurName"/>

bind="PersonGivenName" incremental="true">
Input First Name:

bind="PersonSurName" incremental="true">
Input Last Name:

bind="PersonGivenName">
Output First Name:

bind="PersonSurName">
Output Last Name:

Discussion

Here are the two lines in the model that bind the data element paths to identifiers:

id="PersonGivenName" nodeset="/data/PersonGivenName"/>
id="PersonSurName" nodeset="/data/PersonSurName"/>

Note that bind uses nodeset, not ref to specify the path name to the leaf element in the instance document.

After this is done, each user interface element that inputs or outputs the data elements just adds the bind attribute:

>bind="PersonGivenName"**>

We should also note that in this case there is a single input and a single output for each data element. This does not need to be the case. A single input can be bound to many outputs and an output could also depend on many inputs. An example of this would be using the "calculate" attribute of the bind statement.

Bind attributes

Here are the following attributes of the bind element and a short description of how they are used:

type

  • Associate an instance variable with a specific XML Schema data type
  • Extend or restrict schema type definitions

relevant

  • Enabling or disable controls based on the values of data elements in the model

required

  • Conditionally make fields required based on the values of data elements in the model

readonly

  • Disable editing of fields based on model data elements such as role

constraint

  • Create complex schema constraints between two or more data elements
  • Set the limits of minimum or maximum values of a node-set

calculate

  • Creating computational dependency among data elements
  • Compute the value of new data elements based on other data elements
  • Enable spread-sheet like calculations within XForms

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
XForms, Adder
CC BY-SA 4.0
The model has instance data in it to store the values that the user enters in the form. The view is part of the presentation in the body of the HTML document. ## Sample Program xmlns=" xmlns:xf=" XForms inputs with labels xmlns=""> Enter your first name, and last name. ref="PersonGivenName" incremen
CC BY-SA 4.0
It will need additions if you want to align select, select1, textarea and other controls. A full CSS file for doing this is described later on in this cookbook. Note that you MUST put inputs inside of a group element for this stylesheet to work. Also note that the table can grow if the labels get to
CC BY-SA 4.0
This example has been tested using the FireFox browser. The use of the .xf-value class selector may not work on other systems.
CC BY-SA 4.0
This example uses a CSS style sheet to put the labels and fieldset legend in bold and align the login and password labels. By default the fieldset box stretches the entire width of the page. You can make it static by adding a style attribute with the width set to 250 pixels like this:
CC BY-SA 4.0
There are three message options: - **ephemeral** - a message that just appears briefly and goes away by itself - **modeless** - a message you can ignore for now - **modal** - a message the user must acknowledge before you go on ## Screen Image Here is a sceen image with the ephemeral message showing