Changing section's label dynamically

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Changing section's label dynamically

fbonin
Hi,
I would like to change the labels of a section dynamically based on what the user selected in the form (the user is using a wizard view). Is this possible to do ?

I was thinking of creating a custom xf:action that would update the label as the section changes.

I was able to change the value of an input using this code :

      <xf:action event="xforms-ready">
        <xf:setvalue ref="//mycontrol">working</xf:setvalue>
      </xf:action>

However, it does not work for sections. I am also unable to change the label dynamically of an input field. Is this possible to do also ?

Thank you !
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Changing section's label dynamically

Alessandro  Vernet
Administrator
Hi Frederic,

A couple of questions:

- And is this in the context of a form you created with Form Builder? I.e. you'd like to programmatically change the label of a section, which normally is just entered in Form Builder itself?
- Is your form available in multiple languages, or do you have just 1 language?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Changing section's label dynamically

fbonin
- And is this in the context of a form you created with Form Builder? I.e. you'd like to programmatically change the label of a section, which normally is just entered in Form Builder itself?

Yes, we want to have a generic label and change it only for a certain scenario in the form

- Is your form available in multiple languages, or do you have just 1 language?

Yes (just 2 languages though and it won't grow)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Changing section's label dynamically

Alessandro  Vernet
Administrator
Hi Frederic,

Got it; so, you could, editing the source of the form in Form Builder:

1. Find the <xf:instance> with id="fr-form-resources". In this instance, remove the xxf:readonly="true", so you can programmatically change the content of that instance.

2. Set the value with code along these lines (here assuming this is triggered by a button named `set-label`, and that the control you're setting the label of is named `my-control`.

<xf:action observer="set-label-control" event="DOMActivate">
    <xf:setvalue ref="instance('fr-form-resources')/resource[@xml:lang = 'en']/my-control/label"
                 value="'My value'"/>
</xf:action>

You'll let us know if this works for you,

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Changing section's label dynamically

fbonin
Great that makes sense to modify the resource directly ! I guess I can do the same thing for Ouput Control if I want to change the default label based on a reply from a web service ?

I was trying to modify the label field using xpath instead of accessing the resource. Would it be possible to do it this way instead (I am just curious ) ?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Changing section's label dynamically

Alessandro  Vernet
Administrator
Hi Frederic,

Yes, you can change the label (as well as the hint, help, and alert) for any control using the same technique.

What do you mean by "modify the label field using xpath instead of accessing the resource"? In the `xf:setvalue`, you point to what you want to change using an XPath expression (e.g. `instance('fr-form-resources')/resource[@xml:lang = 'en']/my-control/label`), and the value you want to set using another XPath expression, which in the above example was just a string (`'My value'`).

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Loading...