Search code examples
orbeon

Can I use a property to configure a URL in Explanatory Text?


In Form Builder I have a form that includes an Explanatory Text field. The text includes a link. I want the URL for that link to be different in each environment. For my HTTP Services in forms I am using a property that I have defined as described in this blog post.

Is it possible to use a property to configure the URL in the Explanatory Text?


Solution

  • Once RFE 2427 is implemented, you'll have a real solution to your problem. Right now, the text shown by fr:explanation is entirely static.

    You could work around this though, by creating your own custom model logic that, on form load, replaces a certain string from the text by the value of the property you defined:

    1. In Form Builder, create an Explanatory Text field, and for the URL enter SITEURL.
    2. Still in Form Builder, edit the source of the form to remove the xxf:readonly="true" on the fr-form-resources instance. This is the resulting form.
    3. In your properties-local.xml add a custom model logic: <property as="xs:anyURI" name="oxf.fr.detail.model.custom.*.*" value="oxf:/forms/resources/model.xml"/>.
    4. Still in the properties-local.xml, define the value of the placeholder with a property: <property as="xs:string" name="com.example.siteurl" value="http://www.orbeon.com/"/>.
    5. In the model.xml, on form load, replace SITEURL by the value of the property.

    And here is the content of the model.xml:

    <xf:model xmlns:xf="http://www.w3.org/2002/xforms"
              xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
        <xf:action event="xforms-model-construct-done">
            <xf:action iterate="instance('fr-form-resources')/resource/text-with-link/text">
                <xf:setvalue ref="."
                             value="
                                replace(
                                    .,
                                    'SITEURL',
                                    xxf:property('com.example.siteurl')
                                )"/>
            </xf:action>
        </xf:action>
    </xf:model>