How to make custom control based on dynamic data dropdown in orbeon form builder

571 views Asked by At

I have another problem. I want to create new custom control, which is almost the same as Dynamic Data Dropdown. The difference is that user instead of typing in control details data like this:

should pass only

  • Dictionary - ABCDE

and the rest of the URL and other data should be default and remembered in the control. So instead of 4 input fields (url, item, label, value) there should be only 1 (dictionary). I already figuraed out how to remove these input fields and add the one that I want:

I simply replaced this part of code:

                <xf:input ref="@resource">
                    <xf:label lang="en">Resource URL</xf:label>
                    <xf:label lang="es">URL del Recurso</xf:label>
                    <xf:label lang="fi">Resurssi URL</xf:label>
                    <xf:label lang="fr">URL de la ressource</xf:label>
                    <xf:label lang="ru">URL ресурса</xf:label>
                    <xf:label lang="it">URL della risorsa</xf:label>
                    <xf:label lang="de">URL der Ressource</xf:label>
                    <xf:label lang="sv">Resursens adress</xf:label>
                    <xf:label lang="nl">Resource URL</xf:label>
                    <xf:label lang="pt">URL do Recurso</xf:label>
                    <xf:hint lang="en">HTTP URL returning data used to populate the dropdown</xf:hint>
                    <xf:hint lang="es">HTTP URL retornando datos para poblar la lista</xf:hint>
                    <xf:hint lang="fi">HTTP URL palauttaa pudotusvalikon täyttämiseen käytettyä dataa</xf:hint>
                    <xf:hint lang="fr">URL HTTP auquel réside le service</xf:hint>
                    <xf:hint lang="ru">HTTP URL сервиса, данными из которого будет заполнен выпадающий список</xf:hint>
                    <xf:hint lang="it">URL HTTP che da i dati per il menu a tendina</xf:hint>
                    <xf:hint lang="de">HTTP URL die die Inhalte für das Dropdown-Menü liefert</xf:hint>
                    <xf:hint lang="sv">Vanligen en Internetadress som börjar med http://</xf:hint>
                    <xf:hint lang="nl">HTTP URL als bron voor de gegevens in de selectie</xf:hint>
                    <xf:hint lang="pt">HTTP URL devolvendo dados para preencher a lista de opções</xf:hint>
                </xf:input>
                <xf:input ref="xf:itemset/@ref">
                    <xf:label ref="$resources/dialog-actions/items/label"/>
                    <xf:hint ref="$resources/dialog-actions/items/hint"/>
                </xf:input>
                <xf:input ref="xf:itemset/xf:label/@ref">
                    <xf:label ref="$resources/dialog-actions/item-label/label"/>
                    <xf:hint ref="$resources/dialog-actions/item-label/hint"/>
                </xf:input>
                <xf:input ref="xf:itemset/xf:value/@ref">
                    <xf:label ref="$resources/dialog-actions/item-value/label"/>
                    <xf:hint ref="$resources/dialog-actions/item-value/hint"/>
                </xf:input> 

with this:

<xf:input ref="@resource">
                    <xf:label lang="en">Dictionary</xf:label>

                    <xf:hint lang="en">Dictionary returning data used to populate the dropdown</xf:hint>
                </xf:input>

And now I have no idea how to store the default values which should be remembered and how to bind them to the methods so it can retrieve elements from the url to my dropdown control. Please help

1

There are 1 answers

1
piechos On

Ok, I've done something like this:

<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:my="http://www.example.com/"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:xbl="http://www.w3.org/ns/xbl"
         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

    <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
        <display-name lang="en">Custom Controls</display-name>
    </metadata>

    <xbl:binding id="my-dictionary-selector" element="my|dictionary-selector" xxbl:mode="lhha binding value">
        <fb:metadata>
            <fb:display-name lang="en">Dictionary Selector</fb:display-name>
            <fb:icon lang="en">
                <fb:small-icon>/forms/orbeon/builder/images/dropdown.png</fb:small-icon>
                <fb:large-icon>/forms/orbeon/builder/images/dropdown.png</fb:large-icon>
            </fb:icon>
            <fb:template>
                <my:dictionary-selector>
                    <xf:label ref=""/>
                    <xf:hint ref=""/>
                    <xf:help ref=""/>
                    <xf:alert ref=""/>
                        <xf:itemset ref="()">
                            <xf:label ref="()"/>
                            <xf:value ref="()"/>
                        </xf:itemset>
                </my:dictionary-selector>
            </fb:template>
            <fb:control-details>
                <xf:input ref="@resource" name="aa">
                    <xf:label lang="en">Dictionary</xf:label>
                    <xf:hint lang="en">Dictionary name returning data used for the suggestions</xf:hint>
                </xf:input>
            </fb:control-details>
        </fb:metadata>
        <xbl:template>
            <xf:select1 appearance="minimal" ref="xxf:binding('my-dictionary-selector')">
                <xf:item>
                    <xf:label>[Select...]</xf:label>
                    <xf:value/>
                </xf:item>
                <xf:itemset nodeset="doc('http://localhost:8080/OrbeonForm/resources/dictionaries/colors')/collection/dictionary">
                    <xf:label ref="key"/>
                    <xf:value ref="value"/>
                </xf:itemset>
            </xf:select1>
        </xbl:template>
    </xbl:binding>


</xbl:xbl>

and it works (takes values from the given xml), but now I want to give the user oportunity to choose the name of dictionary. So in URL to the xml file (http://localhost:8080/form/resources/dictionaries/colors), in place of colors, I want to insert string which user put in dictionary input in control details. How can I achieve it? Is it gonna change dropdown list after user click apply in control details?