W3C home > Mailing lists > Public > www-forms@w3.org > February 2003

Re: Problem with shopping cart design in XForms

From: David Landwehr <dlandwehr@novell.com>
Date: Mon, 24 Feb 2003 12:46:52 +0100
Message-ID: <005701c2dbfa$6d5b4480$6c0b9e0a@hoff>
To: "joern turner" <joern.turner@web.de>, <www-forms@w3.org>
Hi Joern,

Conditional processing is tricky. One solution to your problem could be the
following:
 * Insert the "add" element
 * Delete the first "add" element which do not fulfill the requirements (if
all is fulfilled the selected nodeset will be of length 0 and none will be
deleted)

I have attached a form which demonstrates the idea.

Best regards,
David


----- Original Message -----
From: "joern turner" <joern.turner@web.de>
To: <www-forms@w3.org>
Sent: Saturday, February 22, 2003 12:18 AM
Subject: Problem with shopping cart design in XForms


> i've got a problem designing a shopping cart in XForms. i hope some of
> the wizards might have a idea how to design such a form in XForms.
>
> the requirements are as follows:
> the user sees a simple list of articles (article-name, article-number,
> amount) and below two inputs (article-number,amount) for adding a new
> item to the list.
>
> the behaviour should be as follows: the user supplies values to the
> inputs and hits 'add'-button. then the constraints (is article-number
> valid + is amount valid) should be checked and ONLY if valid inserted
> into the list.
>
> the instance is as follows:
> <articles>
> <article id="666001">
>          <article-name>gr?atze</article-name>
>          <orderamount>3</orderamount>
> </article>
>          <article id="677033">
>          <article-name>lange Goppels</article-name>
>          <orderamount>1</orderamount>
>          </article>
>          <article id="666031">
>          <article-name>schwere Hutze</article-name>
>          <orderamount>23</orderamount>
>          </article>
> </articles>
> <add articlenummer="" orderamount=""/>
>
> here the problem : is there a way to insert the new item only if its
valid?
>
> i'm running out of ideas - any help greatly appreaciated.
>
> Joern Turner
>
> i've attached the complete source for a deeper look.
>
>


----------------------------------------------------------------------------
----


<?xml version="1.0" encoding="iso-8859-1"?>
<envelope xmlns:chiba="http://chiba.sourceforge.net/2001/09/xforms"
    chiba:css-style="ic3i.css" chiba:id="address" chiba:name="ShoppingCart"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xforms="http://www.w3.org/2002/08/xforms/cr"
    >
    <xforms:model xforms:id="shoppingcart">
        <xforms:submission xforms:id="submission-1"
xforms:action="dom:/prototype/shoppingcart" xforms:replace="instance"
xforms:method="post"/>

        <xforms:bind xforms:id="bind-customer-article-name"
xforms:nodeset="/shoppingcart/customer/article-name"/>

        <xforms:bind xforms:id="bind-article"
xforms:nodeset="/shoppingcart/articles/article">
        <xforms:bind xforms:id="bind-article-id" xforms:nodeset="@id"
xforms:type="integer" xforms:constraint="number(./text()) > 100"/>
        <xforms:bind xforms:id="bind-article-article-name"
xforms:nodeset="article-name" xforms:type="string"/>
        <xforms:bind xforms:id="bind-article-orderamount"
xforms:nodeset="orderamount" xforms:type="integer"
xforms:constraint="number(./text()) > 0"/>
    </xforms:bind>

        <xforms:bind xforms:id="bind-add-articlenummer"
xforms:nodeset="/shoppingcart/add/@articlenummer" xforms:type="integer"/>
        <xforms:bind xforms:id="bind-add-orderamount"
xforms:nodeset="/shoppingcart/add/@orderamount" xforms:type="integer"/>

        <xforms:instance>
        <!-- shoppingcart -->
            <shoppingcart>
            <customer id="99">
            <name>Testcustomer</name>
            </customer>

            <articles>
            <article id="666001">
            <article-name>gr?atze</article-name>
            <orderamount>3</orderamount>
            </article>
            <article id="677033">
            <article-name>lange Goppels</article-name>
            <orderamount>1</orderamount>
            </article>
            <article id="666031">
            <article-name>schwere Hutze</article-name>
            <orderamount>23</orderamount>
            </article>
            </articles>

            <add articlenummer="" orderamount=""/>

            </shoppingcart>

        </xforms:instance>

    </xforms:model>
    <body>
    <chiba:form>
    <xforms:group>
    <xforms:output xforms:id="out-1" xforms:bind="bind-customer-name">
    <xforms:label xforms:id="label-1">Customername: </xforms:label>
    </xforms:output>

<table>
<tr>
<td><b>ArticleNumber</b></td>
<td><b>Article-Name</b></td>
<td><b>Amount</b></td>
<td></td>
</tr>
    <xforms:repeat xforms:id="repeat-1" xforms:bind="bind-article">
    <tr>
    <td>
<xforms:output xforms:id="out-2" xforms:bind="bind-article-id">
<xforms:alert xforms:id="alert-1">Articlenumber?/xforms:alert>
</xforms:output>
    </td>
    <td>
<xforms:output xforms:id="out-3" xforms:bind="bind-article-article-name"/>
    </td>
    <td>
<xforms:input xforms:id="in-1" xforms:bind="bind-article-orderamount">
<xforms:alert xforms:id="alert-2">Amount must be greater than
1</xforms:alert>
</xforms:input>
    </td>
    <td>
<!--
    <xforms:extension><chiba:selector/></xforms:extension>
    -->
    </td>
</tr>
    </xforms:repeat>
    <tr>
    <td>
<xforms:input xforms:id="in-2" xforms:bind="bind-add-articlenummer"/>
    </td>
    <td>
    </td>
    <td>
<xforms:input xforms:id="in-3" xforms:bind="bind-add-orderamount"/>
    </td>
    <td>
            <xforms:trigger xforms:id="trigger-1">
                <xforms:label
xlink:href="images/add_new.gif">Einf?xforms:label>
                <xforms:action xforms:id="action-1">
                <xforms:revalidate />
                    <xforms:insert xforms:id="insert-1"
xforms:nodeset="/shoppingcart/articles/article"
xforms:at="xforms:count('article')" xforms:position="after"/>
                    <xforms:setValue xforms:id="setvalue-1"
xforms:ref="/shoppingcart/articles/article[xforms:count('article')]/@id"
xforms:value="/shoppingcart/add/@articlenummer"/>
                    <xforms:setValue xforms:id="setvalue-2"
xforms:ref="/shoppingcart/articles/article[xforms:count('article')]/orderamo
unt" xforms:value="/shoppingcart/add/@orderamount"/>
                    <xforms:setValue xforms:id="setvalue-3"
xforms:ref="/shoppingcart/add/@articlenummer" xforms:value="''"/>
                    <xforms:setValue xforms:id="setvalue-4"
xforms:ref="/shoppingcart/add/@orderamount" xforms:value="''"/>
                </xforms:action>
            </xforms:trigger>
    </td>
    </tr>
</table>

    </xforms:group>

<xforms:trigger xforms:id="trigger-3">
<xforms:label xforms:id="label-7">Óderungen speichern</xforms:label>
<xforms:action xforms:id="action-3">
<xforms:send xforms:id="send-1" xforms:submission="submission-1"/>
</xforms:action>
</xforms:trigger>

    </chiba:form>
    </body>
</envelope>



Received on Monday, 24 February 2003 06:43:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:21:54 GMT