values from multiply selection control in second field (as a string)

48 views
Skip to first unread message

Roman Mendaluk

unread,
Sep 21, 2021, 7:25:03 AM9/21/21
to Orbeon Forms

Hi, probably simple question but i cannot afford with it.
My form
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            ...>
    <xhtml:head>
        <xhtml:title>dyrektor</xhtml:title>
        <xforms:model xmlns:fb="http://orbeon.org/oxf/xml/form-builder" id="fr-form-model">
            <xforms:instance id="fr-form-instance">
                <form>
                        <section-1>
                        <checkboxList/>
                        <checkboxListString/>
                    </section-1>
                                    </form>
            </xforms:instance>
            <xforms:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
                         ref="instance('fr-form-instance')">
                <xforms:bind id="section-1-bind" name="section-1" ref="section-1">
                    <xf:bind id="checkboxList-bind" ref="checkboxList" name="checkboxList"/>
                    <xf:bind id="checkboxListString-bind" ref="checkboxListString" name="checkboxListString"/>
                </xforms:bind>
                        </xforms:bind>
           
            </xforms:instance>
           
            <xforms:instance xxf:readonly="true" id="fr-form-resources">
                <resources>
                    <resource xml:lang="en">
                        <checkboxList>
                            <label>checkbox list</label>
                            <hint/>
                            <item>
                                <label>one</label>
                                <hint/>
                                <value>1</value>
                            </item>
                            <item>
                                <label>two</label>
                                <hint/>
                                <value>2</value>
                            </item>
                            <item>
                                <label>three</label>
                                <hint/>
                                <value>3</value>
                            </item>
                        </checkboxList>
                        <checkboxListString>
                            <label>checkbox list string</label>
                            <hint/>
                        </checkboxListString>
                    </resource>
                </resources>
            </xforms:instance>
            <xforms:instance xxf:readonly="true" id="fr-service-request-instance"
                             xxforms:exclude-result-prefixes="#all">
                <request/>
            </xforms:instance>
            <xforms:instance xxf:readonly="true" id="fr-service-response-instance"
                             xxforms:exclude-result-prefixes="#all">
                <response/>
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <fr:view xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
                 xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline"
                 xmlns:xbl="http://www.w3.org/ns/xbl">
            <fr:body xmlns:xh="http://www.w3.org/1999/xhtml">
                <fr:section bind="section-1-bind" id="section-1-control">
                    <xforms:label ref="$form-resources/section-1/label"/>
                    <fr:grid>
                        <xh:tr>
                            <xh:td>
                                <xf:select id="checkboxList-control" appearance="full" bind="checkboxList-bind" class="">
                                    <xf:label ref="$form-resources/checkboxList/label"/>
                                    <xf:hint ref="$form-resources/checkboxList/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                       
                       
                                    <xf:itemset ref="$form-resources/checkboxList/item">
                                        <xf:label ref="label"/>
                                        <xf:value ref="value"/>
                                        <xf:hint ref="hint"/>
                                    </xf:itemset>
                                </xf:select>
                            </xh:td>
                        </xh:tr>
                        <xh:tr>
                            <xh:td>
                                <xf:input id="checkboxListString-control" bind="checkboxListString-bind" class="">
                                    <xf:label ref="$form-resources/checkboxListString/label"/>
                                    <xf:hint ref="$form-resources/checkboxListString/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                       
                                   
                                </xf:input>
                            </xh:td>
                        </xh:tr>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xhtml:body>
</xhtml:html>

Control 'checkboxList' its multiply selection control. Control 'checkboxListString' its text control (string). I'd like to rewrite selected values from first control as a string to second separated by ';' So if i select 1 ale 3 checkbox in checkboxList field i'd like to get 'one;three' in checkboxListString field. I tried various formulas in checkboxListString like

string-join(for $i in tokenize(instance('fr-form-resources')//checkboxList, ' ') return instance('fr-form-resources')//checkboxList/item[value=$i]/label,'; ')

but it doesnt work.
Thank Ypu for help/

Jarosław Kowalewski

unread,
Sep 21, 2021, 7:40:00 AM9/21/21
to orb...@googlegroups.com
As it's space separated list you can simple replace space by space and semicolon. 
replace($list, ' ', '; ') 

Hope this will work. 

//Jarek

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orbeon+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/d4b34894-4dee-4eb3-af33-332b673e3611n%40googlegroups.com.

Jarosław Kowalewski

unread,
Sep 21, 2021, 7:43:30 AM9/21/21
to orb...@googlegroups.com
But if you would like to fix your expression  just change instance name used in for. 
You wrote two times fr-form-resoureces instance id but the first one (after 'in') should be fr-form-instance 

//Jarek
Message has been deleted
Message has been deleted

rmen...@gmail.com

unread,
Sep 22, 2021, 4:06:32 AM9/22/21
to Orbeon Forms
I have changed it but it still doesnt work, this is my formula:
string-join(for $i in tokenize(instance('fr-form-instance')//checkboxList, ' ') return instance('fr-form-resources')//checkboxList/item[value=$i]/label,'; ')

rmen...@gmail.com

unread,
Sep 22, 2021, 4:07:36 AM9/22/21
to Orbeon Forms
Hi Jarek. After using replace formula i have values separated by ';' no the label I need.

Jarosław Kowalewski

unread,
Sep 24, 2021, 12:29:23 PM9/24/21
to orb...@googlegroups.com
Please find demo https://demo.orbeon.com/demo/fr/orbeon/builder/edit/225948f892d050f718e41b99c2cd242d7b78f47b
I changed the formula (ver 1) to not use 'for' as it's not necessary and fixed your formula, see ver 2

Hope this time it works ;)

//Jarek


Message has been deleted

Jarosław Kowalewski

unread,
Sep 27, 2021, 12:34:46 PM9/27/21
to orb...@googlegroups.com
Because you did not correct everything :) Note that in my example there are additional bracets. Before 'for' and ', ' (comma) 
String-join((for loop), 'separator') 


pt., 24 wrz 2021, 18:29 użytkownik Roman Mendaluk <s21...@pjwstk.edu.pl> napisał:
I have changed it but still it doesnt work. This is my formula after correction:
string-join(for $i in tokenize(instance('fr-form-instance')//checkboxList, ' ') return instance('fr-form-resources')//checkboxList/item[value=$i]/label,'; ')


wtorek, 21 września 2021 o 13:43:30 UTC+2 Jarek napisał(a):
Reply all
Reply to author
Forward
0 new messages