Orbeon Forms: Set Multiple Radio Button Values via Button

69 Views Asked by At

We have many forms that are a checklist of tasks for the maintenance technician to perform, say for an annual motor vehicle inspection. Each tasks has a radio-button for the technician confirm whether the task was completed or not (e.g. Done/Not done, or OK/Not OK, etc) and they are all in the same section on the form.

We want button that calls an Action to default all these radio-buttons in the section to OK or Done to speed up the process..

I have tried the following code, but it sets all the Done values, then the 2nd statement clears the Done values and sets the OK values. How can we get it to do both?

<xf:action event="DOMActivate">
  <xf:setvalue xxf:iterate="//SubScn2YearlyMaintenance//*[empty(*)]" value="if (//* != '') then 'Done' else ."/>                                             
  <xf:setvalue xxf:iterate="//SubScn2YearlyMaintenance//*[empty(*)]" value="if (//* != '') then 'OK' else ."/>                                        
</xf:action>  

We know we can set each field individually, but there can be upwards of 50 tasks to perform, and we would want some simple code to set all the Done/OK values if possible.

Example form

Many thanks in advance.

PeteA

2

There are 2 best solutions below

6
avernet On BEST ANSWER

With something along those lines work for you?

<xf:action event="DOMActivate">
    <xf:setvalue
        xxf:iterate="
            //SubScn2YearlyMaintenance
            //*[
                empty() and 
                exists(
                    xxf:itemset(concat(local-name(), '-control'), 'xml')
                    //item/value[. = ('checked')]
                )
            ]"
        value="if (// != '') then 'checked' else ."/>
</xf:action>

PS: This answer has been updated per OP's feedback.

3
David Dejmal On

Based on you example I would suggest to use same value same value for every radio button. You can have difference only in label. Then you can use only one xf:setvalue.

Second sollution is use same prefix/suffix in name to all radio buttons and use in your XPath funciton starts-with() or ends-with(). Result could look like this when rename you OK/Not Ok radio buttons with prefix "OK" :

<xf:setvalue xxf:iterate="//SubScn2YearlyMaintenance//*[starts-with(name(),'OK') and empty(*)]"