Home arrow XML arrow Page 4 - XForms Basics, Part 3

Shop 'till You Drop - XML

XMLIn the previous article, I showed you how to manage user input in the XForms model. I discussed the process of submitting an XForm and more importantly - validating user input prior to submission using built-in XML Schema support. In this concluding article, find out how to use the <xforms:bind> element to perform calculations on form input values, integrate XPath expressions into your XForms model and get a crash course in the XForms event model.

TABLE OF CONTENTS:
  1. XForms Basics, Part 3
  2. Operating with Extreme Caution
  3. Money, Money, Money
  4. Shop 'till You Drop
  5. The Bookworm Turns
  6. An Event to Remember
  7. Link Out
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 14
January 19, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

It's also possible to specify that a particular element of the instance data be read-only via the "readonly" property. Consider the following example:


<!-- form model -->
<xforms:model id="shop">
 
<xforms:instance>
  
<item>
   
<code />
   
<price />
   
<discount>2.00</discount>
   
<quantity />
   
<grossTotal />
   
<netTotal />
  
</item>
 
</xforms:instance>
<xforms:bind nodeset="/item/discount" readonly="true()" />
</xforms:model>

In this case, since you don't want users messing with the discount rate, you can use the "readonly" property to make it non-modifiable. As before, you can combine this with comparison tests to make the property's relevance conditional.

One extremely useful property in this context - and one you'll probably be using a lot - is the "calculate" property, which lets you calculate some of the form data on the fly. Consider the following extension of the example above, which illustrates:


<!-- form model -->
<xforms:model id="shop">
 
<xforms:instance>
  
<item>
   
<code />
   
<price />
   
<discount>2.00</discount>
   
<quantity />
   
<grossTotal />
   
<netTotal />
  
</item>
 
</xforms:instance>
<xforms:bind nodeset="/item/discount" readonly="true()" />
<xforms:bind nodeset="/item/grossTotal" 
calculate
="/item/price */item/quantity" />
<xforms:bind nodeset="/item/netTotal" calculate="/item/grossTotal -
((item/grossTotal * /item/discount)/100)" 
/>
</xforms:model>

In this case, the "calculate" property has been used to dynamically calculate the value of the <grossTotal> element from the values of the <price> and <quantity> elements. The <netTotal> is then again calculated from the <grossTotal> by accounting for the <discount>.

In case you were wondering why I haven't used a "readonly" property for the two dynamically-calculated values; I don't need to, since these values are automatically made read-only when a "calculate" property is used on them.



 
 
>>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: