Hi,
I have two selects on an xform: 1) Car brand 2) Car model I would like to populate the model based on the brand selected. Can someone show me how to do this? Thanks, Assaf -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Assaf
It depends on you XML layout, if you have nested selections like <instance> <selectedBrand/> <selectedModel/> <brand> <title>Some Brand Title</title> <value>somebrandvalue <model> <title>Some Model Title</title> <value>somemodelvalue</value> </model> ... </brand> ... </instance> The first would be something like: <xforms:select1 ref="/instance/selectedBrand"> <xforms:label>Brand: </xforms:label> <xforms:itemset ref="/instance/brand"> <xforms:label ref="title"/> <xforms:value ref="value"/> </xforms:itemset> </xforms:select> The second one contains an xpath relating to the first <xforms:select1 ref="/instance/selectedModel"> <xforms:label>Model: </xforms:label> <xforms:itemset ref="/instance/brand[. = /instance/selectedBrand]/model"> <xforms:label ref="title"/> <xforms:value ref="value"/> </xforms:itemset> </xforms:select1> This should give a good start, the only problem is when changing the brand you will have to do a setvalue to change the model to the first in the list otherwise it will go blank or show the first value in the list, but not store that value in the instance. Hope this helps Ryan Ryan Puddephatt Software Engineer Teleflex Group - IT UK 1 Michaelson Square Livingston West Lothian Scotland EH54 7DP e> [hidden email] t> +44(0)1506 407 110 f> +44(0)1506 407 108 -----Original Message----- From: [hidden email] [mailto:[hidden email]] Sent: 20 July 2006 11:42 To: [hidden email] Subject: [ops-users] Populating a select based on another value Hi, I have two selects on an xform: 1) Car brand 2) Car model I would like to populate the model based on the brand selected. Can someone show me how to do this? Thanks, Assaf -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Hi,
Thanks for the reply. The issue is that I need to populate based on a db query. Here is what I managed to write but does not work (the second select stays with xxx). My code is based on selecting a country and then a region based on the country. view.xsl: <xforms:instance id="instance"> <xi:include href="model.xml"/> </xforms:instance> <xforms:instance id="countries"> <xi:include href="input:data"/> </xforms:instance> <xforms:instance id="ship-from-regions"> <regions> <region> <name>xxx</name> <id>12</id> </region> </regions> </xforms:instance> <xforms:instance id="ship-to-regions"> <regions> <region> <name>yyy</name> <id>www</id> </region> </regions> </xforms:instance> <!-- Submission when ship_from_country changed --> <xforms:submission id="ship-from-country-updated" ref="instance('instance')/ship_from_country_id" method="post" action="/requests/moving/list-regions" replace="instance" instance="ship-from-regions"/> <td> <xforms:select1 ref="ship_from_country_id" appearance="minimal"> <xforms:itemset nodeset="instance('countries')/country"> <xforms:label ref="name"/> <xforms:value ref="id"/> </xforms:itemset> <xforms:send submission="ship-from-country-updated" ev:event="xforms-value-changed"/> </xforms:select1> </td> <xforms:select1 ref="ship_from_region_id" appearance="minimal"> <xforms:itemset nodeset="instance('ship-from-regions')/region"> <xforms:label ref="name"/> <xforms:value ref="id"/> </xforms:itemset> </xforms:select1> list-regions.xpl: <p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:oxf="http://www.orbeon.com/oxf/processors"> <p:param name="instance" type="input"/> <p:processor name="oxf:sql"> <p:output name="data" id="xml-response"/> <p:input name="instance" href="#instance"/> <p:input name="config"> <sql:config> <sql:connection> <sql:datasource>logistics</sql:datasource> <regions> <sql:execute> <sql:query> select * from regions where country_id = <sql:param type="xs:string" select="doc('input:instance')/moving/ship_from_country_id"/> and active=1 order by name asc</sql:query> <sql:result-set> <sql:row-iterator> <region> <name> <sql:get-column-value type="xs:string" column="name"/> </name> <id> <sql:get-column-value column="id"/> </id> </region> </sql:row-iterator> </sql:result-set> </sql:execute> </regions> </sql:connection> </sql:config> </p:input> </p:processor> <!-- Generate response --> <p:processor name="oxf:xml-serializer"> <p:input name="data" href="#xml-response"/> <p:input name="config"> <config> <content-type>application/xml</content-type> </config> </p:input> </p:processor> </p:config> model.xml: <moving> <ship_from_country_id/> <ship_from_region_id/> </moving> -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Assif you will need to make the second one update! The xpath
"instance('ship-from-regions')/region" makes no reference to the result of the first select1, each region will have to have a country id so if the XML was <regions> <region> <name>xxx</name> <id>12</id> <country-code>45</country-code> </region> </regions> Then the xpath would be instance('ship-from-regions')/region[country-code = instance('instance')/ship_from_country_id] Ryan Ryan Puddephatt Software Engineer Teleflex Group - IT UK 1 Michaelson Square Livingston West Lothian Scotland EH54 7DP e> [hidden email] t> +44(0)1506 407 110 f> +44(0)1506 407 108 -----Original Message----- From: [hidden email] [mailto:[hidden email]] Sent: 20 July 2006 19:07 To: [hidden email] Subject: Re: RE: [ops-users] Populating a select based on another value Hi, Thanks for the reply. The issue is that I need to populate based on a db query. Here is what I managed to write but does not work (the second select stays with xxx). My code is based on selecting a country and then a region based on the country. view.xsl: <xforms:instance id="instance"> <xi:include href="model.xml"/> </xforms:instance> <xforms:instance id="countries"> <xi:include href="input:data"/> </xforms:instance> <xforms:instance id="ship-from-regions"> <regions> <region> <name>xxx</name> <id>12</id> </region> </regions> </xforms:instance> <xforms:instance id="ship-to-regions"> <regions> <region> <name>yyy</name> <id>www</id> </region> </regions> </xforms:instance> <!-- Submission when ship_from_country changed --> <xforms:submission id="ship-from-country-updated" ref="instance('instance')/ship_from_country_id" method="post" action="/requests/moving/list-regions" replace="instance" instance="ship-from-regions"/> <td> <xforms:select1 ref="ship_from_country_id" appearance="minimal"> <xforms:itemset nodeset="instance('countries')/country"> <xforms:label ref="name"/> <xforms:value ref="id"/> </xforms:itemset> <xforms:send submission="ship-from-country-updated" ev:event="xforms-value-changed"/> </xforms:select1> </td> <xforms:select1 ref="ship_from_region_id" appearance="minimal"> <xforms:itemset nodeset="instance('ship-from-regions')/region"> <xforms:label ref="name"/> <xforms:value ref="id"/> </xforms:itemset> </xforms:select1> list-regions.xpl: <p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:oxf="http://www.orbeon.com/oxf/processors"> <p:param name="instance" type="input"/> <p:processor name="oxf:sql"> <p:output name="data" id="xml-response"/> <p:input name="instance" href="#instance"/> <p:input name="config"> <sql:config> <sql:connection> <sql:datasource>logistics</sql:datasource> <regions> <sql:execute> <sql:query> select * from regions where country_id = <sql:param type="xs:string" select="doc('input:instance')/moving/ship_from_country_id"/> and active=1 order by name asc</sql:query> <sql:result-set> <sql:row-iterator> <region> <name> <sql:get-column-value type="xs:string" column="name"/> </name> <id> <sql:get-column-value column="id"/> </id> </region> </sql:row-iterator> </sql:result-set> </sql:execute> </regions> </sql:connection> </sql:config> </p:input> </p:processor> <!-- Generate response --> <p:processor name="oxf:xml-serializer"> <p:input name="data" href="#xml-response"/> <p:input name="config"> <config> <content-type>application/xml</content-type> </config> </p:input> </p:processor> </p:config> model.xml: <moving> <ship_from_country_id/> <ship_from_region_id/> </moving> -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |