XML
  Home arrow XML arrow Page 4 - XForms Basics, Part 3
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XForms Basics, Part 3
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2004-01-19

    Table of Contents:
  • XForms Basics, Part 3
  • Operating with Extreme Caution
  • Money, Money, Money
  • Shop 'till You Drop
  • The Bookworm Turns
  • An Event to Remember
  • Link Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    XForms Basics, Part 3 - Shop 'till You Drop
    (Page 4 of 7 )

    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


     

       

    XML ARTICLES

    - 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...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway