I am trying to find out how to change the control visibility of a text box at runtime for an Orbeon form. At the following sample, I have created an image button - when the user clicks on this button I wish to show / hide another button but unfortunately my code is not working properly:
<xf:trigger>
<xf:label>
<xf:output value="concat('<img src=''http://**********:8081/green-light.png', image, '''>')"
mediatype="text/html"/>
</xf:label>
<xxf:script event="DOMActivate">
var remarksControl = ORBEON.jQuery('*[id $= "remarks-control"]')[0];
remarksControl.hidden= true;
</xxf:script>
</xf:trigger>
</fr:c>
<fr:c y="1" x="7" w="6">
</fr:c>
<fr:c x="1" y="2" w="6">
<xf:input id="remarks-control" bind="remarks-bind">
<xf:label ref="$form-resources/remarks/label"/>
<xf:hint ref="$form-resources/remarks/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</fr:c>
What is the best approach to implement this kind of functionality? What I am actually trying to achieve is to have a form with several images and the user when clicks on an image she will be able to activate / deactivate several text fields on the form.
Thanks in advance
I would try to avoid using JavaScript to handle a case like this. The button is bound to an element, just like any other control. So you write some XForms that stores a value, say show-textfield
, when the button is clicked. Assuming your button is named button
, you can do so with the following custom model:
<xf:model xmlns:xf="http://www.w3.org/2002/xforms">
<xf:action
observer="button-control"
event="DOMActivate">
<xf:setvalue ref="event('xxf:binding')">show-textfield</xf:setvalue>
</xf:action>
</xf:model>
Then the control you want to show upon the button being clicked can have the Visibility formula $button = 'show-textfield'
. As a result, you'll get a result like: