XForms/Insert with Origin
Appearance
< XForms
Motivation
[edit | edit source]You want to insert new values into an instance of the model and specify where to find the initial values of the insert.
Method
[edit | edit source]You can add an origin attribute to the insert statement to tell XForms where to get the initial data for the insert. This is the preferred method over doing many setvalues. The syntax of the insert is the following:
<xf:insert ev:event="DOMActivate"
nodeset="instance('persons')/Person"
at="last()" position="after"
origin="instance('init')/Person"/>
Screen Image
[edit | edit source]A sample screen image. Many people do not have the ability to run the examples so this is critical.
Use this format:
Make SURE you label all images with a license. Please use creative commons "share alike 3.0 with attribution" if you can.
XForms Application
[edit | edit source]Make sure that the mime-type is set in the svn system to be text/xml.
Sample XForms Template
[edit | edit source]<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<title>Insert with Origin</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family:Helvetica, sans-serif}
</style>
<xf:model>
<xf:instance xmlns="" id="persons">
<data>
<Person>
<PersonGivenName>John</PersonGivenName>
<PersonFamilyName>Doe</PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
<Person>
<PersonGivenName>Sue</PersonGivenName>
<PersonFamilyName>Smith</PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
</data>
</xf:instance>
<xf:bind nodeset="XFormsAwareIndicator" type="xs:boolean"/>
<!-- initial values for new Person records -->
<xf:instance xmlns="" id="init">
<data>
<Person>
<PersonGivenName></PersonGivenName>
<PersonFamilyName></PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
</data>
</xf:instance>
</xf:model>
</head>
<body>
<h3>Insert with Origin</h3>
<xf:repeat nodeset="Person" id="person-repeat">
<xf:input ref="PersonGivenName">
<xf:label>First Name: </xf:label>
</xf:input>
<xf:input ref="PersonFamilyName">
<xf:label>Family Name: </xf:label>
</xf:input>
<xf:select1 ref="PersonGenderCode">
<xf:label>Gender: </xf:label>
<xf:item>
<xf:label>Male</xf:label>
<xf:value>male</xf:value>
</xf:item>
<xf:item>
<xf:label>Female</xf:label>
<xf:value>female</xf:value>
</xf:item>
<xf:item>
<xf:label>Unknown</xf:label>
<xf:value>unknown</xf:value>
</xf:item>
</xf:select1>
<xf:input ref="XFormsAwareIndicator">
<xf:label>Indicator: </xf:label>
</xf:input>
</xf:repeat>
<xf:trigger>
<xf:label>Add</xf:label>
<xf:insert ev:event="DOMActivate" nodeset="instance('persons')/Person" at="last()" position="after"
origin="instance('init')/Person"/>
</xf:trigger>
</body>
</html>