Search code examples
formsorbeonxforms

Orbeon/XForms: Change dropdown values based on other input control


I have a text control my-text and a dropdown my-dropdown. Depending on the content of my-text, the itemset of my-dropdown should change. Unfortunately, there is no visibility property for individual dropdown items, so I thought of a different solution. Inside the <resource xml:lang="en"> tag of my Orbeon form i defined several itemsets:

<first-itemset>
    <item>
        <label>AAA</label>
        <value>a</value>
    </item>
    <item>
        <label>BBB</label>
        <value>b</value>
    </item>
</first-itemset>


<second-itemset>
    <item>
        <label>XXX</label>
        <value>x</value>
    </item>
    <item>
        <label>YYY</label>
        <value>y</value>
    </item>
</second-itemset>

Now if content of my-text equals "first-itemset" then the first itemset should be used, otherwise the second. How can I do that? Inside <fr:dropdown-select1 ...> I need something like

<xf:itemset ref="$form-resources/CONTENT_OF_MY-TEXT_HERE/item">
    <xf:label ref="label"/>
    <xf:value ref="value"/>
</xf:itemset>

What do I need to write instead of CONTENT_OF_MY-TEXT_HERE to get the actual content so orbeon uses the correct itemset?


Solution

  • The direct answer to your question is: *[local-name() = xxf:value('choice-control')]. So you would have:

    <xf:itemset 
        ref="
            $form-resources/
            *[local-name() = xxf:value('choice-control')]/
            item
        ">
    

    With this, you'd get a different itemset depending the value typed in the choice control:

    Different itemset based on other control

    However, keep in mind that if you're doin this in Form Builder, your change to the source can be lost quite easily. For instance, next time you change the control name, that ref expression will be reset. So, it would be better to find another way to achieve this. For instance, you could have 2 dropdowns, of which only one is visible at any point in time, based on the value enterer in the other field.