First up, the definition of the XForms model: unlike the previous example, I've defined the instance data tree in a separate file and imported it via the "src" attribute.
Here's what "immigration.xml" looks like: <!-- immigration.xml --> <immigrant> <name /> <citizenship /> <purpose /> <immunization /> <address /> </immigrant> You've already seen how to use an <xforms:input> element in previous examples, so I won't go into the details again. Do note, however, my usage of the <xforms:label> and <xforms:hint> elements within it. These come in handy to provide descriptive human-readable information about the control.
The <xforms:select1> element allows the user to select one item from a series of options:
Within the <xforms:select1> element, the list of available choices is defined via one or more <xforms:item> elements, each of which must have a label and value; the former is displayed to the user and the latter is passed to the server on submission. A special "appearance" attribute in the <xforms:select1> element can be used to control the display of the element in the browser ("full" for a list of all values, "minimal" for a minimum number of values, and "compact" for a scrollable list). Similar, though not identical to the above, is the <xforms:select> element, which allows the user to select more than one value from the options available.
As before, the choices are defined via a series of <xforms:label> and <xforms:value> elements, while the "appearance" attribute can be used to control the appearance of the control ("full" for a list of all values, "minimal" for a minimum number of values, and "compact" for a scrollable list). Finally, the <xforms:textarea> element is used to display a multi-line text entry box, suitable for use with large blocks of text.
And here's what it all looks like:
Now, all this is fine and dandy, but how about submitting the form and actually doing something with the user's data? Well, that's a whole new kettle of fish, one which involves jumping through a complicated series of hoops involving the <xsd:submission> element. I don't plan to discuss it now. Instead, I'm going to defer it to the second segment of this tutorial and encourage you to spend the interim playing with the various form controls to understand how they work. Each control comes with specific properties that can be used to customize its behavior, so take a look at the specification, get comfortable with them, try out a couple of implementations, and come back next week to take the next step in our XForms journey! Note: Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article.
blog comments powered by Disqus |
|
|
|
|
|
|
|