Binding validation & type to xbl component model elements

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

Binding validation & type to xbl component model elements

bwallis42
I am writing a control (simplified version shown below) that adds rows to a table for the user to enter data into. This data will eventually be used to draw a graph in the control (using Flot).

I cannot work out how to bind validations and types to the entries created in the model. I want to make entries in the first column of type xf:date so I get a date picker and I want to calculate the value for entry two. I also need to validate the five entries for not empty and some relationships (within a range, etc.).

So, how do I bind to the model entries? I've tried various bind statements like
<bind nodeset="date" type="xf:date" />
in various places but I cannot get it to work.

Thanks.

<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
    xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:exf="http://www.exforms.org/exf/1-0"
    xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
    xmlns:saxon="http://saxon.sf.net/" xmlns:im="http://www.infomedix.com.au/cpf/forms" xmlns:xbl="http://www.w3.org/ns/xbl"
    xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">


    <fb:metadata>
        <fb:display-name lang="en">CPF Controls</fb:display-name>
    </fb:metadata>

    <xbl:binding id="im-growth-chart" element="im|growth-chart" xxbl:mode="lhha binding">
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">Growth Chart</display-name>
            <icon lang="en">
            </icon>
            <template>
                <im:growth-chart id="" ref="" xmlns="">
                    <xf:label ref="" />
                    <xf:hint ref="" />
                    <xf:help ref="" />
                    <xf:alert ref="$fr-resources/detail/labels/alert" />
                </im:growth-chart>
            </template>

        </metadata>
        <xbl:resources>
            <xbl:style src="/xbl/im/growth-chart/growth-chart.css" />
        </xbl:resources>
        <xbl:template>
            <!-- Internal model -->
            <xf:model id="local-model">   
                <!-- Growth chart info row prototype -->
                <xf:instance id="chart-row-prototype">
                    <row xmlns="">
                        <date />
                        <age />
                        <length />
                        <weight />
                        <headCircumference />
                    </row>
                </xf:instance>
            </xf:model>

            <xf:group id="im-component-group" model="local-model">

                <xf:var name="binding" value="xxf:binding('im-growth-chart')" />

                <div class="im-graph-data-table" xmlns="http://www.w3.org/1999/xhtml">
                    <table>
                        <tr>
                            <th style="width: 20%">Date</th>
                            <th style="width: 20%">Age (months)</th>
                            <th style="width: 20%">Length (cm)</th>
                            <th style="width: 20%">Weight (kg)</th>
                            <th style="width: 20%">Head Circumference (cm)</th>
                        </tr>
                        <xf:repeat nodeset="$binding/row">
                            <tr>
                                <td>
                                    <xf:input ref="date" />
                                </td>
                                <td>
                                    <xf:input ref="age" />
                                </td>
                                <td>
                                    <xf:input ref="length" />
                                </td>
                                <td>
                                    <xf:input ref="weight" />
                                </td>
                                <td>
                                    <xf:input ref="headCircumference" />
                                </td>
                            </tr>
                        </xf:repeat>
                    </table>
                    <xf:trigger>
                        <xf:label>Add</xf:label>
                        <xf:action ev:event="DOMActivate">
                            <xf:insert context="$binding" origin="xxf:instance('chart-row-prototype')" />
                        </xf:action>
                    </xf:trigger>
                </div>
            </xf:group>
        </xbl:template>
    </xbl:binding>
</xbl:xbl>
Reply | Threaded
Open this post in threaded view
|

Re: Binding validation & type to xbl component model elements

Alessandro  Vernet
Administrator
Hi Brian,

You're binding your xf:input inside the XBL to a node outside of the XBL (with Form Runner, in fr-form-instance, in fr-form-model). This means that you would need the xf:bind to be in fr-form-model, so Form Builder would need to insert those binds to the form when the component is added. You can instruct Form Builder to insert certain attributes on the bind it adds when your component is added (e.g. see number.xbl), but that capability doesn't go far enough for your case.

So, instead, I recommend that instead of directly binding your controls to nodes in fr-form-instance, you bind them to an internal instance, and use xxbl:mirror="true" on that instance to have the XForms engine mirror the content of that instance into the node the component is bound to. This way, because your controls will be bound to an instance inside the XBL, you'll be able to use xf:bind inside the XBL. See wpaint.xbl for example of how to use that mirroring capability.

Alex

On Mon, May 18, 2015 at 10:06 PM, bwallis42 <[hidden email]> wrote:
I am writing a control (simplified version shown below) that adds rows to a
table for the user to enter data into. This data will eventually be used to
draw a graph in the control (using Flot).

I cannot work out how to bind validations and types to the entries created
in the model. I want to make entries in the first column of type xf:date so
I get a date picker and I want to calculate the value for entry two. I also
need to validate the five entries for not empty and some relationships
(within a range, etc.).

So, how do I bind to the model entries? I've tried various bind statements
like

in various places but I cannot get it to work.

Thanks.



--
View this message in context: http://discuss.orbeon.com/Binding-validation-type-to-xbl-component-model-elements-tp4659946.html
Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
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 [hidden email].
To post to this group, send email to [hidden email].

--
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 [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Binding validation & type to xbl component model elements

bwallis42
Hi Alex,
  Thanks. That works, now I am able to update and validate my model. Onto the next problem! :-)

Reply | Threaded
Open this post in threaded view
|

Re: Binding validation & type to xbl component model elements

Alessandro  Vernet
Administrator
Hi Brian,

Excellent, I'm glad it is working; you're getting to use some pretty advanced features there! ;)

Alex

On Thu, May 21, 2015 at 11:43 PM, bwallis42 <[hidden email]> wrote:
Hi Alex,
  Thanks. That works, now I am able to update and validate my model. Onto
the next problem! :-)



--
View this message in context: http://discuss.orbeon.com/Binding-validation-type-to-xbl-component-model-elements-tp4659946p4659971.html
Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
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 [hidden email].
To post to this group, send email to [hidden email].

--
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 [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet