Binding issue - single component with multiple fields

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

Binding issue - single component with multiple fields

yougo
Hallo,

I'm trying to create a very simple xpl for a component to run in form builder.

The component should display two fields, an amount and a currency combo box, and I need to write them in separate xml fields e.g.:

<amount>1000</amount>
<currency>USD</amount>

I guess the problem is I didn't really understand how to bind data...

The xbl I wrote:
money-xbl.txt

What I get from edit source in form builder:
money-xbl-generated.txt

What I need:
money-xbl-desired.txt

PS. already read the books tutorial many times... but with no luck

Thanks in advance
Ugo
Reply | Threaded
Open this post in threaded view
|

Re: Binding issue - single component with multiple fields

Alessandro  Vernet
Administrator
Hi Ugo,

With the upcoming Orbeon Forms 4.0, you can tell Form Builder about those additional elements (<amount/> and <currency/>) you want to be inserted in the instance. You do so by having, in your XBL, in the metadata for Form Builder, instead of:

    <template>
        <fr:variablemoney>
            <xforms:label ref="" />
            <xforms:hint ref="" />
            <xforms:help ref="" />
            <xforms:alert ref="" />
        </fr:variablemoney>
    </template>

The following:

    <templates>
        <instance xmlns="">
            <amount/>
            <currency/>
        </instance>
        <view>
            <fr:variablemoney>
                <xforms:label ref="" />
                <xforms:hint ref="" />
                <xforms:help ref="" />
                <xforms:alert ref="" />
            </fr:variablemoney>
        </view>
    </templates>

Notice how there are now two parts to the template: the part that goes in the instance and one that goes in the view. You can see the updated XBL file: variablemoney.xbl. And as mentioned before, this requires a 4.0 build, so until the final release is out, you can use a milestone build:

http://wiki.orbeon.com/forms/doc/developer-guide/release-notes/40#TOC-4.0-Milestones

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

Re: Binding issue - single component with multiple fields

yougo
Thank you Alessandro for your reply!

I already have the Orbeon Forms version 4 from git.
I used the file corrected by you and now I can see the desired xml in the instance part.

What I still cannot have it to work is the binding. I read tons of posts and docs and it seems to me that for this very easy binding I don't have to write any complex thing, I should just need to tell the xforms:input (or similar) in the xbl:template to point the field defined in the instance with the ref attribute. The ref attribute should be enough for xforms to copy the value from page to instance and viceversa, right?

Unfortunately, when I change something in my component shown in FB nothing is written in the instance (the attached file was copy&pasted from view source after inserting data in the component).

I also noticed that there's no mention to the binding of the two fields (amount and currency in the binding section)...

money-OF4-genratex.txt

thank you
Ugo
Reply | Threaded
Open this post in threaded view
|

Re: Binding issue - single component with multiple fields

Alessandro  Vernet
Administrator
Hi Ugo,

The good news is that the code for your component can be much simpler than what it used to be. You don't need to have a local model, and don't need to worry about scopes. Also, with xxbl:mode="lhha binding", the XBL engine takes care copying the label, help, hint, and alert ("lhha") where needed, and handle the ref/bind/model on your component. Here is the updated component: variablemoney.xbl.

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

Re: Binding issue - single component with multiple fields

yougo
Thank you so much Alessandro!

Now it works, the custom xml is written in the instance part and the binding is handled magically without any additional coding from my side.

I'm still getting an error "An error has occurred in Form Runner" as soon as the fields (textbox or combo) get the focus. The error is not showing anymore after setting some value in the fields (or changing the default value in the combo). I guess there's still some issue with null values, I'm now trying to figure that out.

thank you
Ugo
Reply | Threaded
Open this post in threaded view
|

Re: Binding issue - single component with multiple fields

Alessandro  Vernet
Administrator
Hi Ugo,

Somehow, I don't get this here. I created an empty form, added that XBL control in Form Builder, published it, opened the new page, and can focus on the field and enter a value without getting an error. Maybe this is something that got fixed very recently? Maybe you can try again with a fresh nightly build?

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