开发者

how do i populate another control from the value of another in Xforms?

开发者 https://www.devze.com 2023-03-14 18:37 出处:网络
I am currently developing an archive system with XForms and am a beginner. I have two forms and t开发者_运维百科hey have a common field that needs to be populated with the same value i.e the value of

I am currently developing an archive system with XForms and am a beginner. I have two forms and t开发者_运维百科hey have a common field that needs to be populated with the same value i.e the value of the second form's field depends on the value entered in the first form. I want this entry to be done automatically, when I fill the first form then I don't have to enter that value again in the second form. Since I am saving to a MySQL database, I need both fields to populate their corresponding tables in the database. How would you do this?


Generally, you have two options to create such a workflow: Using the FormBuilder/ FormRunner (but since i don't use them, i can't help you with those), or "by hand" using XML pipelines and e.g. the SQL Processor to interact with SQL databases.

  • XML pipelines (XPL) let you process XML data, for example creating chunks of XML based on session data, XML or SQL databases or XML web services. XPL is similar to XProc, but gives access to additional modules called processors:

  • Processors, for example the SQL processor, provide an "interface" to interact with SQL databases, making available the full range of SQL CRUD operations.

If both forms you're talking of are part the same xforms:model, you can connect them using the technique described by Phil.

If they aren't, you will need to make the xforms:instance data of form 1 persistent before navigating to form 2. Usually, xforms:submissions are used to send data to the persistence layer. You will have to create the following elements:

  • a xforms:submission element inside the xforms:model of form 1, sending the instance data to a certain xpl pipeline (called xpl 1);
  • xpl 1 to write the data to the sql database: at least a sql processor component is needed to build and send the required sql command. you could add a xslt processor if you need to preprocess the instance data.
  • xpl 2 to read from the sql database: same as xpl 1, just the other way. Splitting the read operation (xpl 2) from writing to the sql db (xpl 1) has the advantage of higher flexibility, making form 2 more independent from form 1.
  • in your form 2, you can initialize the instance using xpl 2. There are different ways to initialize the xforms:instance described in the Wiki.

Using those components, you can create very flexible workflows.


You could use the setvalue action and the xforms-value-changed event:

<xf:input bind="foo">
    <xf:label>First control:</xf:label>
    <xf:setvalue ev:event="xforms-value-changed" bind="bar" value="context()" />
</xf:input>

<xf:input bind="bar">
    <xf:label>Second control:</xf:label>
    <xf:setvalue ev:event="xforms-value-changed" bind="foo" value="context()" />
</xf:input>

Alternatively, you could use the calculate attribute on the bind element:

<xf:bind nodeset="instance('bar')/slave" calculate="instance('foo')/master" />

Note that this second approach would have the effect of making the control(s) that bind to the node read-only, which may not be your intention.

EDIT: Looks like I completely misunderstood your question. Ignore me, sorry.

0

精彩评论

暂无评论...
验证码 换一张
取 消