I am trying to change a validation constraint alert by concatenating a request value but at this moment I have not found the key.
I have followed this example: http://discuss.orbeon.com/Changing-section-s-label-dynamically-td4661767.html
My control is like this:
<fr:c x="9" y="1" w="2" h="1">
<xf:input id="my-field-control"
bind="my-field-bind"
class="my-field">
<xf:label ref="$form-resources/my-field/label"/>
<xf:hint ref="$form-resources/my-field/hint"/>
<xf:alert ref="$form-resources/my-field/alert[1]"
validation="validation-82-validation"/>
<xf:alert ref="$form-resources/my-field/alert[2]"
validation="validation-61-validation"/>
<xf:alert ref="$form-resources/my-field/alert[3]"
validation="validation-79-validation"/>
<xf:alert ref="$form-resources/my-field/alert[4]"
validation="validation-80-validation"/>
<xf:alert ref="$form-resources/my-field/alert[5]"
validation="validation-81-validation"/>
<xf:alert ref="$form-resources/my-field/alert[6]"/>
<xf:action ev:event="xforms-ready">
<xf:setvalue ref="instance('fr-form-resources')/resources/resource[#xml:lang = 'es']/my-field/alert[1]"
value="concat(instance('fr-form-resources')/resources/resource[#xml:lang = 'es']/my-field/alert[1],xxf:get-request-parameter('my-request-parameter'))"/>
<xf:setvalue ref="instance('fr-form-resources')/resources/resource[#xml:lang = 'ca']/my-field/alert[1]"
value="concat(instance('fr-form-resources')/resources/resource[#xml:lang = 'ca']/my-field/alert[1],xxf:get-request-parameter('my-request-parameter'))"/>
</xf:action>
</xf:input>
</fr:c>
<xf:instance id=""fr-form-resources"" xxf:readonly=""false"" xxf:exclude-result-prefixes=""#all"">
<resources>
<resource xml:lang=""es"">
<my-field>
<label>my field</label>
<hint/>
<alert>Message</alert>
<alert>Message</alert>
<alert>Message</alert>
<alert>Message</alert>
<alert>Alert to change programatically</alert>
<alert/>
</my-field>
</resource>
<resource xml:lang=""ca"">
<my-field>
<label>my field</label>
<hint/>
<alert>Message</alert>
<alert>Message</alert>
<alert>Message</alert>
<alert>Message</alert>
<alert>Alert to change programatically</alert>
<alert/>
</my-field>
</resource>
</resources>
</xf:instance>
When I change the value of the field, constraints are launched and request parameter is present because is used to check the constraint which its label I want to change but the validation message is always 'Alert to change programatically' not 'Alert to change programatically + my-request-parameter value'.
Your approach of reacting to the xforms-ready event to update the instance with the resources makes sense. However, to run, your handler needs to be inside the <xf:model>, as xforms-ready is an event dispatched to models.
To debug this, you can also insert <xf:message value="…"> in your action, to check that code runs, and to check that certain expressions indeed return the value you expect.
Related
Is there a way to check if a control value is valid (a value is present if required and the value is valid)? I have tried using xf:valid and xxf:valid, but none work as I expected (seem to have to change another, unrelated control for it to redo the calculate value.
2016.2 form builder example form - email-valid value correct once change value of control-5.
<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">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<email-required/>
<email/>
<email-valid/>
<control-5/>
</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="email-required-bind" name="email-required" ref="email-required"
xxf:whitespace="trim"/>
<xf:bind id="email-bind" ref="email" name="email" type="xf:email" xxf:whitespace="trim"
required="//email-required ne ''"/>
<xf:bind id="email-valid-bind" ref="email-valid" name="email-valid"
calculate="if (xxf:valid(//email)) then 'good' else 'bad'"/>
<xf:bind id="control-5-bind" ref="control-5" name="control-5" 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>TEST</application-name>
<form-name>TEST</form-name>
<title xml:lang="en">Untitled Form</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">
<section-1>
<label>Untitled Section</label>
</section-1>
<email-required>
<label>Email Required?</label>
<hint/>
</email-required>
<email>
<label>Emal</label>
<hint/>
</email>
<email-valid>
<label>Email Valid</label>
<hint/>
</email-valid>
<control-5>
<label>Random Field</label>
<hint/>
</control-5>
</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: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>
<xf:input id="email-required-control" bind="email-required-bind">
<xf:label ref="$form-resources/email-required/label"/>
<xf:hint ref="$form-resources/email-required/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
<xh:td>
<xf:input id="email-control" bind="email-bind">
<xf:label ref="$form-resources/email/label"/>
<xf:hint ref="$form-resources/email/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:output id="email-valid-control" bind="email-valid-bind">
<xf:label ref="$form-resources/email-valid/label"/>
<xf:hint ref="$form-resources/email-valid/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:output>
</xh:td>
<xh:td>
<xf:input 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:input>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
The reason this happens is the processing model in XForms:
First, data is updated and recalculated.
Second, data is revalidated.
So if you make a calculation dependent on validation, you can get into the kind of cycle you are seeing, namely that things don't happen in the order you expect. This could, possibly, be fixed by a more subtle dependency algorithm (see also this RFE), but currently this is how things must happen.
In these situations, you could use actions, something like:
<xf:setvalue
observer="email-valid-control"
event="xforms-valid"
ref="bind('email-valid-bind')"
value="true()"/>
<xf:setvalue
observer="email-valid-control"
event="xforms-invalid"
ref="bind('email-valid-bind')"
value="false()"/>
This is heavier, and requires you to use custom model logic, but it's the only reliable way right now.
The default behavior of this button is to be enabled always, and if a field is mandatory or incorrect, an error is shown.
But if you use the wizard, and you have to fill up different sections, it is not normal to submit the form if you are still at the beginning of the form. Probably you must navigate to all sections to fill up all questions (at least the mandatory ones) until you reach the last section. When you are in the last section, you can submit the form. At least, force the user to read all the form.
I know that is a little annoying this behaviour, specially with user with no so much experience with Orbeon, that are inclined to press this button when they have finished the first section.
Then the question is: there is any way of hide or disable the "send" button until the last section is reached?
EDIT
As shown in documentation page the new version 2016.1 of Orbeon finally hides the "submit" button. At least, this text is shown:
Wizard improvements. The wizard's table of contents indicates pages with errors more clearly. In validated mode, pages which cannot be navigated to are also indicated better. Last but not least, in validated mode, Save, Submit, Send, and other buttons which appear within the wizard only show when the user reaches the last page of the wizard. Finally, we made a few cosmetic improvements as well.
I am trying this new feature enabling validation mode, in the properties file:
<!-- Configure wizard layout -->
<property as="xs:string" name="oxf.fr.detail.view.appearance.*.*" value="wizard"/>
<property as="xs:boolean" name="oxf.xforms.xbl.fr.wizard.validate.*.*" value="true"/>
And I have created a simple form using the Form Builder:
<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>Wizard Test</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>
<control-2/>
<control-3/>
</section-1>
<section-4>
<control-5/>
<control-6/>
</section-4>
<section-7>
<control-8/>
</section-7>
</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-2-bind" ref="control-2" name="control-2" required="true()"/>
<xf:bind id="control-3-bind" ref="control-3" name="control-3"/>
</xf:bind>
<xf:bind id="section-4-bind" ref="section-4" name="section-4">
<xf:bind id="control-5-bind" ref="control-5" name="control-5" required="true()"/>
<xf:bind id="control-6-bind" ref="control-6" name="control-6"/>
</xf:bind>
<xf:bind id="section-7-bind" ref="section-7" name="section-7">
<xf:bind id="control-8-bind" ref="control-8" name="control-8" type="xs:boolean"
required="true()"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>WizardTest</application-name>
<form-name>WizardTest</form-name>
<title xml:lang="en">Wizard Test</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 -->
<xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<control-8>
<label>Yes or no?</label>
<hint/>
</control-8>
<control-5>
<label>Radio Button Other</label>
<hint/>
<item>
<label>First choice</label>
<value>1</value>
<hint/>
</item>
<item>
<label>Second choice</label>
<value>2</value>
<hint/>
</item>
<item>
<label>Third choice</label>
<value>3</value>
<hint/>
</item>
</control-5>
<control-6>
<label>Select</label>
<hint/>
<item>
<label>First choice</label>
<value>1</value>
</item>
<item>
<label>Second choice</label>
<value>2</value>
</item>
<item>
<label>Third choice</label>
<value>3</value>
</item>
</control-6>
<control-2>
<label>Radio Button</label>
<hint/>
<item>
<label>First choice</label>
<value>1</value>
<hint/>
</item>
<item>
<label>Second choice</label>
<value>2</value>
<hint/>
</item>
<item>
<label>Third choice</label>
<value>3</value>
<hint/>
</item>
</control-2>
<control-3>
<label>Radio Button Other</label>
<hint/>
<item>
<label>First choice</label>
<value>1</value>
<hint/>
</item>
<item>
<label>Second choice</label>
<value>2</value>
<hint/>
</item>
<item>
<label>Third choice</label>
<value>3</value>
<hint/>
</item>
</control-3>
<section-1>
<label>Untitled Section</label>
</section-1>
<section-4>
<label>Section2</label>
<help/>
</section-4>
<section-7>
<label>Section3</label>
<help/>
</section-7>
</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: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>
<xf:select1 id="control-2-control" appearance="full" bind="control-2-bind">
<xf:label ref="$form-resources/control-2/label"/>
<xf:hint ref="$form-resources/control-2/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="$form-resources/control-2/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<fr:open-select1 xmlns:xxbl="http://orbeon.org/oxf/xml/xbl" 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:itemset ref="$form-resources/control-3/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</fr:open-select1>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
<fr:section id="section-4-control" bind="section-4-bind">
<xf:label ref="$form-resources/section-4/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:open-select1 xmlns:xxbl="http://orbeon.org/oxf/xml/xbl" 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:itemset ref="$form-resources/control-5/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</fr:open-select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<fr:box-select xmlns="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="control-6-control"
bind="control-6-bind">
<xf:label ref="$form-resources/control-6/label"/>
<xf:hint ref="$form-resources/control-6/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="$form-resources/control-6/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</fr:box-select>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
<fr:section id="section-7-control" bind="section-7-bind">
<xf:label ref="$form-resources/section-7/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:yesno-input xmlns="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
id="control-8-control"
bind="control-8-bind">
<xf:label ref="$form-resources/control-8/label"/>
<xf:hint ref="$form-resources/control-8/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</fr:yesno-input>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
I expect then, that in this example, the submit button is hidden and only appears in the last section, when all the other sections are filled up. But I cannot see the submit button when I reach the end of the form.
I also have tried enabling only a set of buttons adding this line to the properties file:
<property as="xs:string" name="oxf.fr.detail.buttons.*.*" value="wizard-prev wizard-next submit"/>
But the "submit" button in this case is always visible.
Is there something I have skipped?
Yes, this would make a lot of sense. Unfortunately, as of this writing this isn't possible. However, on the bright side, this one of the "top RFE" for the product, so I think there is a good chance that it will be implemented "soon". If you'd like to be notified when there is something new for this, you can subscribe yourself to issue #940: Better way to control buttons visibility/readonlyness.
I was interested in getting the documentId when submitting a form and link it to an user (i.e. by the email that is on a mandatory field of the form). The idea is to also call a webservice and send both fields to have this relationship. For now, I want to see this value in a field.
First of all, I have found that I can achieve this using xxforms:instance('fr-parameters-instance')/document but I have not success.
After this, I see here that now (I am using Orbeon 4.9) is changed to fr:document-id() but seems that I am still not able to see the document id in a simple field of the form. Bassically, something like:
<xf:action ev:event="xforms-submit">
<xf:setvalue ref="instance('fr-form-instance')/somefield" value="fr:document-id()"/>
</xf:action>
Simple example created with Form Builder:
<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>Send OrbeonID</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/>
</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>Biit</application-name>
<form-name>SendOrbeonID</form-name>
<title xml:lang="en">Send OrbeonID</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>Write something:</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>
<!-- Form is sent -->
<xf:action ev:event="xforms-submit">
<xf:setvalue ref="instance('fr-form-instance')/section-1/control-1" value="fr:document-id()"/>
</xf:action>
</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">
<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>
</xh:html>
Theorically, If I fill up the input field and press the submit or save button, the field must be updated with the document id. But I am not able to see any value.
The good news is that the document id is already sent as a URL parameter by default. The URL parameter name is document. See also the relevant documentation.
At the end the way I have found to send the document Id is changing the behaviour of the buttons in Orbeon.
In the save as draft button:
<property as="xs:string" name="oxf.fr.detail.process.save-draft.*.*">
save
then send("oxf.fr.detail.save-draft.success")
then success-message("save-draft-success")
recover error-message("database-error")
</property>
And define the send action to somewhere outside of Orbeon:
<property as="xs:boolean" name="oxf.fr.detail.new.accept-post.*.*" value="true" />
<property as="xs:string" name="oxf.fr.detail.save-draft.success.uri.*.*" value="http://localhost:8080/get-id.jsp?document={xxf:instance('fr-parameters-instance')/document}"/>
<property as="xs:string" name="oxf.fr.detail.save-draft.success.method.*.*" value="post"/>
The JSP page get-id.jsp now is executed each time that the user save the draft of the form, but the browser is not redirected to the JSP page.
Changing to use a webservice or other action must be easy.
When you set your form builder controls calculated value to
xxf:instance('fr-parameters-instance')/document
you can get the document id.
I found a few questions related to my problem (Orbeon index of repeat in repeatable section, Orbeon relevant properties and Orbeon nested repeats), but I couldn't get any of them to work properly.
I define a repeatable section with a couple of questions inside and a some relevant rules. I also define some events to manage the visibility of the questions. The problem appears when I create several repeated groups. When I select one of the answers, the relevant rules and the events are launched for all the questions with the same xpath route.
So, my question is: Is there a way to manage the same events ans the same relevant rules for repeatable sections?. That is, could I define some kind of dynamic route based on the index of the section that the user is selecting at the moment and use it in the relevant rules and the events?
The complete code used for the example is below:
<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:meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<xh:title>Test_repeatable</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>Test_app</application-name>
<form-name>Test_repeatable_v1</form-name>
<title xml:lang="en">Test_repeatable</title>
<description xml:lang="en">Description of the form.</description>
<singleton>false</singleton>
</metadata>
</xf:instance>
<xf:instance id="fr-form-instance">
<form>
<Category>
<Group>
<Group-iterator>
<Question/>
<Question2/>
<Question3/>
</Group-iterator>
</Group>
</Category>
</form>
</xf:instance>
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="Category-bind" name="Category" ref="/form/Category">
<xf:bind id="Group-bind" name="Group" ref="/form/Category/Group">
<xf:bind id="Group-iterator-bind" name="Group-iterator"
ref="/form/Category/Group/Group-iterator">
<xf:bind id="Question-bind" name="Question" ref="Question" required="true()"/>
<xf:bind id="Question2-bind"
name="Question2"
readonly="false"
ref="Question2"
relevant="/form/Category/Group/Group-iterator/Question='Answer'"
required="true()"/>
<xf:bind id="Question3-bind"
name="Question3"
readonly="false"
ref="Question3"
relevant="/form/Category/Group/Group-iterator/Question='Answer2' or instance('visible')/Group/Group-iterator/Question2 != 'false' "
required="true()"/>
</xf:bind>
</xf:bind>
</xf:bind>
</xf:bind>
<xf:instance id="fr-form-attachments">
<attachments>
<css filename="" mediatype="text/css" size=""/>
<pdf filename="" mediatype="application/pdf" size=""/>
</attachments>
</xf:instance>
<xf:instance id="fr-form-resources" xxf:readonly="false">
<resources>
<resource xml:lang="en">
<Category>
<label>Category</label>
<hint/>
<alert/>
<Group>
<label>Group</label>
<hint/>
<alert/>
<Question>
<label>Question</label>
<hint/>
<alert/>
<item>
<label>Answer</label>
<hint/>
<value>Answer</value>
</item>
<item>
<label>Answer2</label>
<hint/>
<value>Answer2</value>
</item>
</Question>
<Question2>
<label>Question2</label>
<hint/>
<alert/>
</Question2>
<Question3>
<label>Question3</label>
<hint/>
<alert/>
</Question3>
</Group>
</Category>
</resource>
</resources>
</xf:instance>
<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:instance xxf:readonly="true" id="Group-template">
<Group-iterator>
<Question/>
<Question2/>
<Question3/>
</Group-iterator>
</xf:instance>
<!-- Keep track of visible/hidden status -->
<xf:instance id="visible">
<visible>
<Category>0</Category>
<Group>
<Group-iterator>
<Question>false</Question>
<Question2>false</Question2>
<Question3>false</Question3>
</Group-iterator>
</Group>
</visible>
</xf:instance>
<!-- Change the visibility status for 'Question'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question-control"
ref="instance('visible')/Group/Group-iterator/Question"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question-control"
ref="instance('visible')/Group/Group-iterator/Question"
value="'false'"/>
<!-- Update category showed elements count for 'Question'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
<!-- Change the visibility status for 'Question2'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'false'"/>
<!-- Update category showed elements count for 'Question2'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question2-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question2-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
<!-- Change the visibility status for 'Question3'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question3-control"
ref="instance('visible')/Group/Group-iterator/Question3"
value="'true'"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question3-control"
ref="instance('visible')/Group/Group-iterator/Question3"
value="'false'"/>
<!-- Update category showed elements count for 'Question3'. -->
<xf:setvalue ev:event="xforms-enabled" observer="Question3-control"
ref="instance('visible')/Category"
value="instance('visible')/Category + 1"/>
<xf:setvalue ev:event="xforms-disabled" observer="Question3-control"
ref="instance('visible')/Category"
value="instance('visible')/Category - 1"/>
</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"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel">
<fr:section bind="Category-bind"
id="Category-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/alert"/>
<fr:section bind="Group-bind"
id="Group-control"
max="100"
min="1"
repeat="content"
template="instance('Group-template')">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/alert"/>
<xh:tr>
<xh:td>
<xf:select1 appearance="full" bind="Question-bind"
id="Question-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question/alert"/>
<xf:itemset
ref="instance('fr-form-resources')/resource/Category/Group/Question/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input bind="Question2-bind"
id="Question2-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question2/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question2/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question2/alert"/>
</xf:input>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input bind="Question3-bind"
id="Question3-control">
<xf:label mediatype="text/html"
ref="instance('fr-form-resources')/resource/Category/Group/Question3/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Group/Question3/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Group/Question3/alert"/>
</xf:input>
</xh:td>
</xh:tr>
</fr:section>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
EDIT: A little explanation of the code above.
This example has two sections, one normal and inside of it one repeatable.
Inside the repeatable section there are three questions. The first question has two answers. When I select the first answer the form runner must show the questions two and three. When the second answer is selected the runner must show only the third question. This works correctly if I only have one repeatable section.
The problem appears when I create a new repeatable section. If I select the answer one of the first question, the following questions are shown at the same time in both repeatable groups. The same when I select answer two.
So the question is: Is there a way to tell the Orbeon runner that it must apply the relevant rules only to the repeatable group where the event happens?
EDIT 2: Ok, your solution is working perfect in the case of 'Question2'.
The problem comes with Question 3. If you check the code for Question3 you can see that I try to access also another instance:
relevant="$Question='Answer2' or instance('visible')/Group/Group-iterator/Question2 != 'false' "
The 'visible' instance is not related with any control or bind, is only used for storing an internal value for the questions and is updated using xforms events, as you can see in the code below:
<xf:setvalue ev:event="xforms-enabled"
observer="Question2-control"
ref="instance('visible')/Group/Group-iterator/Question2"
value="'true'"/>
Thus, my new question is: Is there a way to store different values for different iterations of a repeatable section in a static instance and accessing them using a dynamic path (like in your first response with the $)?
If in the xf:bind for Question2 you want to refer to the value of Question in the same iteration, then just use $Question. In fact, as a rule of thumb, you can always refer to the value of another control gaga as $gaga, and trust that the right thing will happen. (At least it will in most cases.) So, your xf:bind for Question2 will become:
<xf:bind id="Question2-bind" name="Question2"
readonly="false" ref="Question2"
relevant="$Question='Answer'"
required="true()"/>
Why is it that when I set the 'oxf.xforms.cache.document' property to false in my local properties file, dynamic labels for buttons and fieldsets no longer seem to update correctly.
I am using the following xform to test this:
<xhtml:html xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
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">
<xhtml:head>
<xhtml:title>Dynamic label</xhtml:title>
<xf:model id="m-default">
<xf:instance id="i-default">
<default xmlns="">
<in />
</default>
</xf:instance>
<xxf:var name="input" value="instance('i-default')/in" />
</xf:model>
</xhtml:head>
<xhtml:body>
<xhtml:h1>Dynamic label</xhtml:h1>
<xf:group ref="instance('i-default')" appearance="xxf:fieldset">
<xf:label>
<xf:output value="count(instance('i-default')[in != ''])" />
</xf:label>
<xf:input ref="$input" incremental="true">
<xf:label>
<xf:output value="'Input: '" />
</xf:label>
</xf:input>
<xhtml:div>
<xf:group ref=".[$input != '']">
<xf:trigger>
<xf:label>
<xf:output value="$input" />
</xf:label>
</xf:trigger>
</xf:group>
</xhtml:div>
</xf:group>
</xhtml:body>
When the property is set to true and I type something in the input field, the label of the fieldset will update to 1 and the button will appear with a label containing the same text as the input field. When the property is set to false the button will appear when I type something the first time, but the fieldset label will not update to 1 and any subsequent entries will not change the label on the button anymore.
Tested this with Orbeon 4.6.0.201406210117-CE.
For reference this is a bug and we have entered an issue here.