How to count the number of duplicate repeated grid - orbeon 2020.1CE - orbeon

It needs to implement a mechanism that will count the number of repeated grids and send the value to the dedicated cell (named x).
If check box - First choice is unchecked, repeated grid is hidden and cell x must show "0".
If check box - First choice is checked, repeated grid become visible and cell x must show "1", and increase by 1 for each addition of repeated grid.
What expression I need to use in cell x?

If in your repeated grid you have a field named first-name, the expression count($first-name) used in a control outside of the repeated grid returns the number of rows in your repeated grid. Assuming your checkbox field is named checkbox, your expression would look like:
if ($checkbox/string() = 'true')
then count($first-name)
else 0
You can find the source of a test form that shows this in action below, and at runtime you get something like:
<xh:html xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xf="http://www.w3.org/2002/xforms">
<xh:head>
<xh:title>Counting the number of rows in a repeated grid</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true" xxf:analysis.calculate="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<grid-1>
<checkbox question-identifier="">true</checkbox>
<count question-identifier=""/>
</grid-1>
<grid-2>
<grid-2-iteration>
<first-name question-identifier=""/>
</grid-2-iteration>
</grid-2>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="grid-1-bind" ref="grid-1" name="grid-1">
<xf:bind id="count-bind" name="count" ref="count" xxf:whitespace="trim"
calculate="if ($checkbox/string() = 'true')
then count($first-name)
else 0"
readonly="false()"/>
<xf:bind id="checkbox-bind" ref="checkbox" name="checkbox" type="xf:boolean"/>
</xf:bind>
<xf:bind id="grid-2-bind" ref="grid-2" name="grid-2"
relevant="$checkbox/string() = 'true'">
<xf:bind id="grid-2-iteration-bind" ref="grid-2-iteration" name="grid-2-iteration">
<xf:bind id="first-name-bind" ref="first-name" name="first-name" xxf:whitespace="trim"/>
</xf:bind>
</xf:bind>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance id="fr-form-metadata" xxf:readonly="true" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>a</application-name>
<form-name>a</form-name>
<title xml:lang="en">Counting the number of rows in a repeated grid</title>
<description xml:lang="en"/>
<created-with-version>2019.1-SNAPSHOT PE</created-with-version>
<library-versions>
<orbeon>1</orbeon>
<app>2</app>
</library-versions>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments/>
</xf:instance>
<!-- All form resources -->
<xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<checkbox>
<label>Show repeated grid</label>
<hint/>
</checkbox>
<count>
<label>Count</label>
<hint/>
</count>
<first-name>
<label>First name</label>
<hint/>
</first-name>
<section-1>
<label>Untitled Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance xxf:readonly="true" id="grid-2-template" xxf:exclude-result-prefixes="#all">
<grid-2-iteration>
<first-name/>
</grid-2-iteration>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-section" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid id="grid-1-grid" bind="grid-1-bind">
<fr:c y="1" x="1" w="6">
<fr:checkbox-input id="checkbox-control" bind="checkbox-bind">
<xf:label ref="$form-resources/checkbox/label"/>
<xf:hint ref="$form-resources/checkbox/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</fr:checkbox-input>
</fr:c>
<fr:c y="1" x="7" w="6">
<xf:input id="count-control" bind="count-bind">
<xf:label ref="$form-resources/count/label"/>
<xf:hint ref="$form-resources/count/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</fr:c>
</fr:grid>
<fr:grid id="grid-2-grid" bind="grid-2-bind" repeat="content" min="1"
template="instance('grid-2-template')"
apply-defaults="true"
fb:initial-iterations="first">
<fr:c x="1" y="1" w="6">
<xf:input id="first-name-control" bind="first-name-bind">
<xf:label ref="$form-resources/first-name/label"/>
<xf:hint ref="$form-resources/first-name/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</fr:c>
<fr:c x="7" y="1" w="6"/>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>

Related

Orbeon Forms: How to populate a control value via an Action

Forgive the simple question, but how can I pass a value into a control via an Action.
What I'm trying to achieve is to display a message popup with two buttons, and depending on the button pressed, I then want to populate a control value:
<xf:action observer="Message1-control" event="DOMActivate">
<xf:label>Alert Button</xf:label>
<xf:message>You pressed the Message 1 button</xf:message>
<!-- Here is where we want to write the value back to a control -->
</xf:action>
I've tried all sorts of synyax, but I'm struggling to get it right
I make demo form for you https://demo.orbeon.com/demo/fr/orbeon/builder/edit/2e978a87be5ce4112d9b008dd481ae935040861c
I use xxf:show and xxf:dialog to show modal popup with two controls. In button in modal I use xf:setvalue to propagate value from input and xxf:hide to hide window.
<xh:html xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xf="http://www.w3.org/2002/xforms">
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true" xxf:analysis.calculate="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<grid-1>
<AgeOutput/>
<BtnShowDialog/>
 <btnDialogBox/>
<textBoxDialog/>
</grid-1>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="grid-1-bind" ref="grid-1" name="grid-1">
<xf:bind id="AgeOutput-bind" name="AgeOutput" ref="AgeOutput" xxf:whitespace="trim"/>
<xf:bind id="BtnShowDialog-bind" ref="BtnShowDialog" name="BtnShowDialog"/>
<xf:bind id="textBoxDialog-bind" name="textBoxDialog" ref="textBoxDialog"
xxf:whitespace="trim"/>
<xf:bind id="btnDialogBox-bind" ref="btnDialogBox" name="btnDialogBox"/>
</xf:bind>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance id="fr-form-metadata" xxf:readonly="true" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>test</application-name>
<form-name>age_dialog</form-name>
<title xml:lang="en">Untitled Form</title>
<description xml:lang="en"/>
<created-with-version>2021.1.6.202211071741 PE</created-with-version>
<library-versions>
<orbeon>14</orbeon>
<app>2</app>
</library-versions>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments/>
</xf:instance>
<!-- All form resources -->
<xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<section-1>
<label>Untitled Section</label>
</section-1>
<AgeOutput>
<label/>
<hint/>
</AgeOutput>
<BtnShowDialog>
<label>Show dialog</label>
<hint/>
</BtnShowDialog>
<textBoxDialog>
<label>Age</label>
<hint/>
</textBoxDialog>
<btnDialogBox>
<label>Send</label>
<hint/>
</btnDialogBox>
</resource>
</resources>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-section" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid id="grid-1-grid" bind="grid-1-bind">
<fr:c y="1" x="1" w="6">
<xf:input id="AgeOutput-control" bind="AgeOutput-bind">
<xf:label ref="$form-resources/AgeOutput/label"/>
<xf:hint ref="$form-resources/AgeOutput/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</fr:c>
<fr:c y="1" x="7" w="6">
<xf:trigger id="BtnShowDialog-control" bind="BtnShowDialog-bind">
<xf:label ref="$form-resources/BtnShowDialog/label"/>
<xf:hint ref="$form-resources/BtnShowDialog/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xxf:show event="DOMActivate" dialog="my-dialog-id"/>
</xf:trigger>
</fr:c>
</fr:grid>
</fr:section>
<xxf:dialog id="my-dialog-id" appearance="full" level="modal" close="true" draggable="true"
visible="false">
<xf:label>Age confirm</xf:label>
<xf:input id="textBoxDialog-control" bind="textBoxDialog-bind">
<xf:label ref="$form-resources/textBoxDialog/label"/>
<xf:hint ref="$form-resources/textBoxDialog/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
<xf:trigger id="btnDialogBox-control" bind="btnDialogBox-bind">
<xf:label ref="$form-resources/btnDialogBox/label"/>
<xf:hint ref="$form-resources/btnDialogBox/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:action event="DOMActivate">
<!-- Operation to perform -->
<xf:setvalue ref="//AgeOutput" value="//textBoxDialog"/>
</xf:action>
<xxf:hide event="DOMActivate" dialog="my-dialog-id"/>
</xf:trigger>
</xxf:dialog>
</fr:body>
</fr:view>
</xh:body>
</xh:html>

Orbeon preselect autocomplete value in reusable component

I'm using Orbeon v2017.1 and I'm trying to create a service within a Section Template which is supposed to retrieve the label of the default country which should be preselected in an autocomplete field (country).
I want to preselect the country only if the user has not entered a value (or, when the form loads). It should support multiple languages.
If I trigger the action after "form loads" and after "the controls are ready", it calls my service but only for the library form. For all other forms which include this reusable section, the service is not called.
Is there some other way this could be achieved? Thanks in advance.
EDIT
Below is an example of an autocomplete field, service, and action which sets the control value
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<xh:head>
<xh:title/>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="all-countries"
src="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<country-dynamic-autocomplete label=""/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="country-dynamic-autocomplete-bind" ref="country-dynamic-autocomplete"
name="country-dynamic-autocomplete"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>insurance</application-name>
<form-name>test</form-name>
<title xml:lang="en"/>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<country-dynamic-autocomplete>
<label>Countries Preselect Value</label>
<hint/>
</country-dynamic-autocomplete>
<section-1>
<label>Country Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance id="get-default-country-value-instance" class="fr-service"
xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="get-default-country-value-submission" class="fr-service"
resource="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/CountryName/XML/debug?sCountryISOCode=DE"
method="get"
serialization="none"
mediatype="none"/>
<xf:action id="set-country-default-value-binding">
<xf:action event="DOMActivate" ev:observer="country-dynamic-autocomplete-control"
if="true()">
<xf:send submission="get-default-country-value-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="get-default-country-value-submission">
<xf:var name="request-instance-name" value="'get-default-country-value-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="get-default-country-value-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'country-dynamic-autocomplete'"/>
<xf:var name="control-value" value="/string"/>
</xf:action>
</xf:action>
</xf:action>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:autocomplete xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="country-dynamic-autocomplete-control"
labelref="#label"
max-results-displayed="300"
resource="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"
bind="country-dynamic-autocomplete-bind">
<xf:label ref="$form-resources/country-dynamic-autocomplete/label"/>
<xf:hint ref="$form-resources/country-dynamic-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/ArrayOftCountryCodeAndName/tCountryCodeAndName">
<xf:label ref="sName"/>
<xf:value ref="sISOCode"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
EDIT 2 (new service):
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<xh:head>
<xh:title/>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="all-countries" src="http://api.worldbank.org/v2/countries/"/>
<!-- Main instance --> <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<country-dynamic-autocomplete label=""/>
<control-3/>
</section-1>
</form>
</xf:instance>
<!-- Bindings --> <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="country-dynamic-autocomplete-bind" ref="country-dynamic-autocomplete"
name="country-dynamic-autocomplete"/>
<xf:bind id="control-3-bind" ref="control-3" name="control-3" xxf:whitespace="trim"/>
</xf:bind>
</xf:bind>
<!-- Metadata --> <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>insurance</application-name>
<form-name>test</form-name>
<title xml:lang="en"/>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments --> <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources --> <!-- Don't make readonly by default in case a service modifies the resources --> <xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<country-dynamic-autocomplete>
<label>Countries Preselect Value</label>
<hint/>
</country-dynamic-autocomplete>
<control-3>
<label>XML</label>
<hint/>
</control-3>
<section-1>
<label>Country Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance id="get-default-country-value-instance" class="fr-service"
xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="get-default-country-value-submission" class="fr-service"
resource="http://restcountries.eu/rest/v2/name/deutschland"
method="get"
serialization="none"
mediatype="none"/>
<xf:instance id="json-to-xml-instance" class="fr-service" xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="json-to-xml-submission" class="fr-service"
resource="http://restcountries.eu/rest/v2/all"
method="get"
serialization="none"
mediatype="none"/>
<xf:action id="show-json-in-xml-binding">
<xf:action event="fr-run-form-load-action-after-controls" ev:observer="fr-form-model"
if="true()">
<xf:send submission="json-to-xml-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="json-to-xml-submission">
<xf:var name="request-instance-name" value="'json-to-xml-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="json-to-xml-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'control-3'"/>
<xf:var name="control-value" value="saxon:serialize(., 'xml')"/>
</xf:action>
</xf:action>
</xf:action>
<xf:action id="set-country-default-value-binding">
<xf:action event="DOMActivate" ev:observer="country-dynamic-autocomplete-control"
if="true()">
<xf:send submission="get-default-country-value-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="get-default-country-value-submission">
<xf:var name="request-instance-name" value="'get-default-country-value-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="get-default-country-value-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'country-dynamic-autocomplete'"/>
<xf:var name="control-value" value="saxon:serialize(., 'xml')"/>
</xf:action>
</xf:action>
</xf:action>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:autocomplete xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="country-dynamic-autocomplete-control"
labelref="#label"
max-results-displayed="300"
resource="http://restcountries.eu/rest/v2/all"
bind="country-dynamic-autocomplete-bind">
<xf:label ref="$form-resources/country-dynamic-autocomplete/label"/>
<xf:hint ref="$form-resources/country-dynamic-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/_/name">
<xf:label ref="name"/>
<xf:value ref="alpha2Code"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input id="control-3-control" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>

Orbeon dynamic dropdown linked to another field

A variation on the sample dynamic dropdown sample using Form Builder, how does one refer the drop down list to the value of another field. I can get the 'debug' text field to change with ../pet , but the item[#group=context()/../pet] is not working as expected.
Note: The 'petnames' model is included but I could not reference it internally so I reference to an external XML file of the same format.
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:exf="http://www.exforms.org/exf/1-0"
fr:data-format-version="4.0.0">
<xh:head>
<xh:title>Example Dynamic data dropdown</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<pet/>
<control-4/>
<mypetname itemset-empty="true"/>
</section-1>
</form>
</xf:instance>
<xf:instance id="petnames">
<root>
<item group="cat" value="Kitty"/>
<item group="cat" value="Garfield"/>
<item group="dog" value="Spot"/>
<item group="dog" value="Rover"/>
<item group="fish" value="Bubbles"/>
<item group="fish" value="Bob"/>
<item group="cobra" value="King"/>
<item group="cobra" value="Shelby"/>
</root>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="pet-bind" ref="pet" name="pet"/>
<xf:bind id="mypetname-bind" ref="mypetname" name="mypetname"/>
<xf:bind id="control-4-bind" ref="control-4" name="control-4" xxf:whitespace="trim"
calculate="../pet"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>samples</application-name>
<form-name>DynamicDataDropdown</form-name>
<title xml:lang="en">Example Dynamic data dropdown</title>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<pet>
<label>Pick a pet</label>
<hint/>
<item>
<label>Cat</label>
<value>cat</value>
</item>
<item>
<label>Dog</label>
<value>dog</value>
</item>
<item>
<label>Fish</label>
<value>fish</value>
</item>
<item>
<label>Cobra</label>
<value>cobra</value>
</item>
</pet>
<control-4>
<label>debug</label>
<hint/>
</control-4>
<mypetname>
<label>Your pet names</label>
<hint/>
</mypetname>
<section-1>
<label>Untitled Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:select1 id="pet-control" bind="pet-bind" appearance="dropdown">
<xf:label ref="$form-resources/pet/label"/>
<xf:hint ref="$form-resources/pet/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="$form-resources/pet/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>
</xh:td>
<xh:td>
<xf:input id="control-4-control" bind="control-4-bind">
<xf:label ref="$form-resources/control-4/label"/>
<xf:hint ref="$form-resources/control-4/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
<xh:td>
<fr:databound-select1 xmlns="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
id="mypetname-control"
resource="http://192.168.0.80/petnames.xml"
bind="mypetname-bind">
<xf:label ref="$form-resources/mypetname/label"/>
<xf:hint ref="$form-resources/mypetname/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/root/item[#group=context()/../pet]">
<xf:label ref="#value"/>
<xf:value ref="#value"/>
</xf:itemset>
</fr:databound-select1>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
You can use the following:
<xf:itemset ref="/root/item[#group = xxf:instance('fr-form-instance')/section-1/pet]">
In this case, context() won't work because the XPath expression in the ref is evaluated inside the XBL component, and doesn't have access to what's outside of the component. In some cases however, it is useful to break the encapsulation, and for those cases the extension function xxf:instance() allows you to do so.

Orbeon Forms: working with xxf:dynamic

I'm trying to add dynamic form with xxf:dynamic on Form Builder (ver. 4.9).
On "builder screen" I see input fields from dynamic instance, but when I want to test it by test button I don't see it at all.
Here is my code:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="dynamic-form">
<xh:html>
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-1>
<control-1/>
<control-3/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds-nowy" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="control-1-bind" name="control-1" ref="control-1"/>
<xf:bind id="control-3-bind" ref="control-3" name="control-3"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<section-1>
<label>Untitled Section</label>
</section-1>
<control-1>
<label>example 1</label>
<hint/>
<alert/>
</control-1>
<control-3>
<label>example 2</label>
<hint/>
</control-3>
</resource>
</resources>
</xf:instance>
<!-- Utility instances for services -->
<xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
<request/>
</xf:instance>
<xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
<response/>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:xbl="http://www.w3.org/ns/xbl">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:input id="control-1-control" bind="control-1-bind">
<xf:label ref="$form-resources/control-1/label"/>
<xf:hint ref="$form-resources/control-1/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
<xh:td>
<xf:input id="control-3-control" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
</xf:instance>
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-1>
<control-1/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="control-1-bind" name="control-1" ref="control-1"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>test</application-name>
<form-name>dynamic_site</form-name>
<title xml:lang="en">Untitled Form</title>
<description xml:lang="en"/>
<singleton>false</singleton>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<section-1>
<label>Untitled Section</label>
</section-1>
<control-1>
<label/>
<hint/>
<alert/>
</control-1>
</resource>
</resources>
</xf:instance>
<!-- Utility instances for services -->
<xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
<request/>
</xf:instance>
<xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
<response/>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<xxf:dynamic ref="instance('dynamic-form')"/>
<fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:xbl="http://www.w3.org/ns/xbl">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:input id="control-1-control" bind="control-1-bind">
<xf:label ref="$form-resources/control-1/label"/>
<xf:hint ref="$form-resources/control-1/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
<xh:td/>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
Unfortunately, the short answer is that <xxf:dynamic> is not documented and should really be considered an internal feature for the use of Form Builder only at this point.

How can I set the relevant property of an Orbeon element to depends on if a previous element is visited or not?

I am trying to create in a form some elements that are visible if one specific element has been visited or not. Is it possible?
At this moment, I only can achieve this copying the relevant part of the first element to the others one, but, in the case on one element depends on many others elements, the relevant rule is too large. Then I am looking for some way to simply this: is there any kind of function like "isVisible()"?
Something like (i.e. control-2 must be visible only if control-1 is visible):
<xf:bind id="control-2-bind" ref="control-2" name="control-2" relevant="isVisible($control-1)"/>
EDITED:
An example of form, where control-5 must be shown only if control-4 is shown.
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance">
<form>
<section-1>
<control-3/>
<control-4/>
<control-5/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="control-3-bind" ref="control-3" name="control-3"/>
<xf:bind id="control-4-bind" ref="control-4" name="control-4"
relevant="$control-3='one'"/>
<xf:bind id="control-5-bind" ref="control-5" name="control-5"
relevant="xxforms:visited($control-4)"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata">
<metadata>
<application-name>asd</application-name>
<form-name>asd</form-name>
<title xml:lang="en">Untitled Form</title>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false">
<resources>
<resource xml:lang="en">
<control-3>
<item>
<label>First choice</label>
<value>one</value>
</item>
<item>
<label>Second choice</label>
<value>two</value>
</item>
<item>
<label>Third choice</label>
<value>three</value>
</item>
<label/>
<hint/>
</control-3>
<control-4>
<label>Input</label>
<hint/>
</control-4>
<control-5>
<label>Visited</label>
<hint/>
</control-5>
<section-1>
<label>Untitled Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<!-- Utility instances for services -->
<xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
<request/>
</xf:instance>
<xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
<response/>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:select1 id="control-3-control" appearance="full" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="$form-resources/control-3/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input id="control-4-control" bind="control-4-bind">
<xf:label ref="$form-resources/control-4/label"/>
<xf:hint ref="$form-resources/control-4/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:output id="control-5-control" bind="control-5-bind">
<xf:label ref="$form-resources/control-5/label"/>
<xf:hint ref="$form-resources/control-5/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:output>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
The code is not working. The control-5 is never shown. What is wrong there?
EDITED: An example using the proposed solution "instance('visited')"
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance">
<form>
<section-1>
<control-3/>
<control-4/>
<control-5/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="control-3-bind" ref="control-3" name="control-3"/>
<xf:bind id="control-4-bind" ref="control-4" name="control-4"
relevant="$control-3='one'"/>
<xf:bind id="control-5-bind" ref="control-5" name="control-5"
relevant="instance('visited') = 'true' and string-length($control-4)>0"/>
</xf:bind>
</xf:bind>
<!-- Keep track of visited status -->
<xf:instance id="visited">
<visited/>
</xf:instance>
<xf:setvalue ev:event="xxforms-visited" observer="control-4-control"
ref="instance('visited')"
value="'true'"/>
<xf:setvalue ev:event="xxforms-unvisited" observer="control-4-control"
ref="instance('visited')"
value="'false'"/>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata">
<metadata>
<application-name>asd</application-name>
<form-name>asd</form-name>
<title xml:lang="en">Untitled Form</title>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false">
<resources>
<resource xml:lang="en">
<control-3>
<item>
<label>First choice</label>
<value>one</value>
</item>
<item>
<label>Second choice</label>
<value>two</value>
</item>
<item>
<label>Third choice</label>
<value>three</value>
</item>
<label/>
<hint/>
</control-3>
<control-4>
<label>Input</label>
<hint/>
</control-4>
<control-5>
<label>Visited</label>
<hint/>
</control-5>
<section-1>
<label>Untitled Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<!-- Utility instances for services -->
<xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
<request/>
</xf:instance>
<xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
<response/>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:select1 id="control-3-control" appearance="full" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="$form-resources/control-3/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input id="control-4-control" bind="control-4-bind">
<xf:label ref="$form-resources/control-4/label"/>
<xf:hint ref="$form-resources/control-4/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:output id="control-5-control" bind="control-5-bind">
<xf:label ref="$form-resources/control-5/label"/>
<xf:hint ref="$form-resources/control-5/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:output>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
In this example, if you select 'First Choice' then, the Input Field is shown. And if you fill it with any value, 'Visited' label is therefore shown. This is the expected behaviour. But, if you later change the Radio Button to 'Second Choice', the Input Field is hidden but the 'Visited' label is still visible (only will be hidden if the user deletes the value of the input field, but now is hidden). This is undesired. There is any way to avoid this?
NOTE: I have added string-length() to be sure that is hidden if the value has been removed. Without it, always is visible.
Since Orbeon Forms 4 there is:
the xxf:visited() function
the xxforms-visited and xxforms-unvisited events
You have to be careful with dependencies when using the function, especially on xf:bind.
I tried to build a naive example, but it turns out that it doesn't work and I entered an issue.
Here is a workaround, which requires adding a custom XForms instance:
<xf:bind id="control-5-bind" ref="control-5" name="control-5"
relevant="instance('visited') = 'true'"/>
<xf:instance id="visited"><visited/></xf:instance>
<xf:setvalue event="xxforms-visited" observer="control-4-control" ref="instance('visited')" value="'true'"/>
<xf:setvalue event="xxforms-unvisited" observer="control-4-control" ref="instance('visited')" value="'false'"/>
And here is the complete example.

Resources