I have an Orbeon app that displays a table of test results and in this table are upload controls that enable the user to upload the data required by for analysis. I setting up this table I need to disable the xforms:upload
control according to the field in my initialization data.
I was trying to use an AVT to invoke display:none style where ever the code finds required="true"
in the instance data - but as far as I can tell this has no effect on the displayed output from Form Runner. Can anyone help please?
My XML data and code is below - please see the xforms:upload
tag for the location of my problem (display: none
):
Sample output:
+------+------+---------------------+------------------------+--------+
| Test | Case | EB Log | COM Log | Status |
+------+------+---------------------+------------------------+--------+
| 022 | 01 | Upload | | |
+------+------+---------------------+------------------------+--------+
| 022 | 02 | Upload | | |
+------+------+---------------------+------------------------+--------+
| 032 | 01 | | Upload | |
+------+------+---------------------+------------------------+--------+
| 032 | 02 | Upload | Upload | |
+------+------+---------------------+------------------------+--------+
| 032 | 03 | Upload | | |
+------+------+---------------------+------------------------+--------+
| 032 | 04 | Upload | | |
+------+------+---------------------+------------------------+--------+
Sample Data:
<test_view>
<test id="022">
<case id="01"><eb_log required="true" filename="" mediatype="" size=""></eb_log><com_log required="false" filename="" mediatype="" size=""></com_log><status>PASS</status></case>
<case id="02"><eb_log required="true" filename="" mediatype="" size=""></eb_log><com_log required="false" filename="" mediatype="" size=""></com_log><status>FAIL</status></case>
</test>
<test id="032">
<case id="01"><eb_log required="false" filename="" mediatype="" size=""></eb_log><com_log required="true" filename="" mediatype="" size=""></com_log><status>none</status></case>
<case id="02"><eb_log required="true" filename="" mediatype="" size=""></eb_log><com_log required="true" filename="" mediatype="" size=""></com_log><status>none</status></case>
<case id="03"><eb_log required="true" filename="" mediatype="" size=""></eb_log><com_log required="false" filename="" mediatype="" size=""></com_log><status>Run</status></case>
<case id="04"><eb_log required="true" filename="" mediatype="" size=""></eb_log><com_log required="false" filename="" mediatype="" size=""></com_log><status>Run</status></case>
</test>
</test_view>
Test code:
<xhtml:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
<xhtml:head>
<xhtml:title>XForms Log Analyser</xhtml:title>
<xforms:model>
<!-- <xforms:instance id="tests-instance" src="test-view.xml" xmlns=""/> -->
<!-- <xforms:submission id="tests-submission" serialization="none" method="get" resource="http://localhost:8080/orbeon/log-analyser/test-view.xml" replace="instance" instance="tests-instance"/> -->
<!-- <xforms:bind nodeset="instance('tests-instance')" type="xs:anyURI"/> -->
<!-- Load tests when the XForms engine is ready -->
<xforms:send ev:event="xforms-ready" submission="list-submission"/>
<!-- Autosave instance data if any value changes in the instance data -->
<xforms:send ev:event="xxforms-value-changed" ev:observer="tests-instance" submission="save-submission"/>
<!-- Instance that contains all the books -->
<xforms:instance id="tests-instance">
<swate_view>
<test id="">
<case id=""><eb_log required="" filename="" mediatype="" size=""></eb_log><com_log required="" filename="" mediatype="" size=""></com_log><status></status></case>
</test>
</swate_view>
</xforms:instance>
<xforms:bind nodeset="instance('tests-instance')"/>
<!-- Submission to load/reset the default data -->
<xforms:submission id="reset-submission" serialization="none"
method="get" action="oxf:/apps/log-analyser/test-view.xml"
replace="instance" instance="tests-instance"/>
<!-- Submission to get the document containing all the tests -->
<xforms:submission id="list-submission" serialization="none"
method="get" action="/exist/rest/db/orbeon/log-analyser/tests.xml"
replace="instance" instance="tests-instance"/>
<!-- Submission to save the document containing all the tests -->
<xforms:submission id="save-submission" ref="instance('tests-instance')"
action="/exist/rest/db/orbeon/log-analyser/tests.xml"
method="put" replace="none">
<xforms:message ev:event="xforms-submit-error" level="modal">An error occurred while saving!</xforms:message>
</xforms:submission>
</xforms:model>
</xhtml:head>
<xhtml:body>
<fr:datatable paginated="true" rowsPerPage="5" maxNbPagesToDisplay="7">
<thead>
<xhtml:tr>
<xhtml:th fr:sortable="true" fr:resizeable="true">Test</xhtml:th>
<xhtml:th fr:sortable="true" fr:resizeable="true">Case</xhtml:th>
<xhtml:th fr:sortable="true" fr:resizeable="true">EB Log</xhtml:th>
<xhtml:th fr:sortable="true" fr:resizeable="true">Com Log</xhtml:th>
<xhtml:th fr:sortable="true" fr:resizeable="true">Status</xhtml:th>
</xhtml:tr>
</thead>
<tbody>
<xhtml:tr repeat-nodeset="test/case">
<xhtml:td>
<xforms:output ref="../@id"/>
</xhtml:td>
<xhtml:td>
<xforms:output value="@id"/>
</xhtml:td>
<xhtml:td>
<!-- <xforms:output value="if(eb_log[@required='true']) then ('Upload') else ('-')"/> -->
**<xforms:upload style="{if(eb_log[@required='false']) then ('display: none')}" ref="eb_log"><xforms:filename ref="@filename"/><xforms:mediatype ref="@mediatype"/><xxforms:size ref="@size"/></xforms:upload>**
</xhtml:td>
<xhtml:td>
<!-- <xforms:output value="if(com_log[@required='true']) then ('Upload') else ('-')"/> -->
**<xforms:upload style="{if(com_log[@required='false']) then ('display: none')}" ref="com_log"><xforms:filename ref="@filename"/><xforms:mediatype ref="@mediatype"/><xxforms:size ref="@size"/></xforms:upload>**
</xhtml:td>
<xhtml:td>
<xforms:output ref="status/text()"/>
</xhtml:td>
</xhtml:tr>
</tbody>
</fr:datatable>
<xforms:submit submission="save-submission">
<xforms:label>Save</xforms:label>
</xforms:submit>
<xforms:submit submission="reset-submission">
<xforms:label>Reset</xforms:label>
</xforms:submit>
</xhtml:body>
</xhtml:html>
A common trick is to use the ref
attribute and place a condition on it. So, your upload will simply look like this:
<xforms:upload ref="com_log[@required = 'false']" ...>
This works because if the condition is false
, then the ref
attribute points to the empty sequence. And a control with a binding pointing to an empty sequence is automatically made non-relevant.