'select' element on XForms

Discussion in 'XML' started by Jonathan, Jan 23, 2004.

  1. Jonathan

    Jonathan Guest

    Does anyone know if it's possible to force a 'select' element (or
    select1) to bind each selected value to a seperate element when
    written to a file, instead of just putting all the values in one
    space-seperated element?

    For example if you had a select (radio) form control for film genres
    and you selected 'Thriller' and 'Action'; when you write this to an
    XML file I would like to get:
    <genre>Thriller</genre><genre>Action</genre>
    instead of <genre>Thriller Action</genre>

    I would appreciate any help at all

    Thanks

    JH
     
    Jonathan, Jan 23, 2004
    #1
    1. Advertisements

  2. I think to achieve that you need an itemset as in the following example:

    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms">
    <head>
    <title>a select element with an itemset</title>
    <xf:model id="main">
    <xf:instance>
    <form-data xmlns="">
    <gods />
    </form-data>
    </xf:instance>
    <xf:submission method="POST"
    action="http://sinex.hut.mediapoli.com:8080/xforms/request" />
    </xf:model>
    <xf:model id="gods">
    <xf:instance>
    <gods xmlns="">
    <god>
    <name>Kibo</name>
    <description>He who greps</description>
    </god>
    <god>
    <name>Xibo</name>
    <description>He who xgreps</description>
    </god>
    <god>
    <name>Lance</name>
    <description>He who bikes</description>
    </god>
    </gods>
    </xf:instance>
    </xf:model>
    </head>
    <body>
    <p>
    <xf:select model="main" ref="gods">
    <xf:label>Favorite gods</xf:label>
    <xf:itemset model="gods" nodeset="god">
    <xf:label ref="description" />
    <xf:copy ref="name" />
    </xf:itemset>
    </xf:select>
    <xf:submit>
    <xf:label>submit data</xf:label>
    </xf:submit>
    </p>
    </body>
    </html>

    When I submit that with XSmiles I get for instance the following data
    submitted:

    <form-data xmlns="" xmlns:xf="http://www.w3.org/2002/xforms">
    <gods><name>Kibo</name><name>Xibo</name></gods>
    </form-data>
     
    Martin Honnen, Jan 24, 2004
    #2
    1. Advertisements

  3. Why have you used <xf:copy ref> instead of <xf:value ref>?
     
    Jonathan Harris, Jan 25, 2004
    #3
  4. Because that is necessary in my understanding to have the element nodes
    posted when the form is submitted:
    http://www.w3.org/TR/xforms/slice9.html#ui-adv-copy
    which says

    Structurally, this element is similar to 8.2.3 The value Element. It
    differs in that it can only be used within itemset, and that it works
    with subtrees of instance data rather than simple values.

    As you asked not for single values but for elements to be submitted I
    think <xf:copy> is needed and the proper way.
     
    Martin Honnen, Jan 25, 2004
    #4
  5. OK, so I need to use copy.
    Problem is, I have never been able to use this as I always get a
    'doesn't conform to DTD\Schema' error message when submitting: when as
    far as I can see it is.
    It might be something to do with the fact that I am using the
    'Formsplayer' plugin instead of XSmiles - which doesn't seem to work at
    all for me. (doesn't render any of the form controls, just puts it all
    in as text)
     
    Jonathan Harris, Jan 26, 2004
    #5
  6. No problem - I have found the solution to my problem.
    Thanks for your help Martin.
     
    Jonathan Harris, Jan 29, 2004
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.