'select' element on XForms

J

Jonathan

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
 
M

Martin Honnen

Jonathan said:
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 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>
 
M

Martin Honnen

Jonathan said:
Why have you used <xf:copy ref> instead of <xf:value ref>?

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.
 
J

Jonathan Harris

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)
 
J

Jonathan Harris

No problem - I have found the solution to my problem.
Thanks for your help Martin.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top