Skip to main content

Binds

Binds

The bind in a xform connects the controls to the Instance.

The binds sits traditionally directly after the Instance

A typical bind is shown below:

 

The bind is linked to the control by its id - dPublishDate

The bind is linked to the instance by its nodeset - dPublishDate

The following attributes are allowed on a bind

id

a reference that ties the bind to the form control.

nodeset

Nodeset is an xPath to the value in the instance to be updated.  Nodesets can contain any valid xPath expressions, to reference attributes etc.  This attribute is concatenated from the parent binds.

required

required can contain an xPath expression which will specify if a field is required.

required="true()" means that content is required to be populated

required="false()" means that content is not required to be populated

required="/nodename[@myvalue='yes']" field is required only if nodename/@myvalue = yes

note: if required is not specified the default is false()

constraint

This can enter a constraint against the validity of the form, a constraint must but return a true / false 

constraint="nodename/@value = ''" bind is only valid when the specified value is empty.

constraint="nodename/@value > '10'" bind is only valid when nodename/@value is greater than 10
constraint="nodename/@value1 = nodename/@value2 '" bind is only valid when nodename/@value1 is the same as nodename/@value1
constraint = "nodename/@value1 !=nodename/@value2" bind is only valid when nodename/@value1 is the unique from nodename/@value2

Note: be aware of the namespace in the instance.

alert

Specify the alert for the resulting constraint.

alert = "Node 1 cannot be the same as Node 2" 

calculate 

This can calculate the value of the node in the instance from other values in the instance.

In this example the xPath will be set to 'tblContent/cContentName'.

type

Type is specified on the bind node as follows:

type=""

The following Types can be verified:

  • String
  • Float, number
  • Date
  • Email
  • imgVerification
  • fileUpload
  • format:RegExp
  • reValidateUser (see below)

 

(code)

The value for required is an xPath expression.  Multiple fields can be compared by setting its value to an expression that will return true for success or false for failure.

reValidateUser checks a password entered in a form against the password of the currently logged in user.  An example use is requiring the user to re-enter their password before a destructive operation.

 
<?xml version="1.0" encoding="utf-8"?>
<Content type="xform" name="EditContent">
	<model>
		<instance>
****
		</instance>
		<submission id="EditContent" action="" method="post" event="return form_check(this)"/>
		<bind nodeset="tblContent">
			<bind id="cContentHeadline" nodeset="cContentName" required="true()" type="string"/>

			<bind id="dPublishDate" nodeset="dPublishDate" required="false()" type="string"/>
			<bind id="dExpireDate" nodeset="dExpireDate" required="false()" type="string"/>
			<bind id="nStatus" nodeset="nStatus" required="true()" type="string"/>
			<bind id="cDescription" nodeset="cDescription" required="false()" type="string"/>
			<bind nodeset="cContentXmlBrief/Content">
				<bind id="cContentHeadline" nodeset="Headline" required="true()" type="string"/>
				<bind id="dPublishDate" nodeset="PublishDate" required="false()" type="string"/>
				<bind id="cContentStrapline" nodeset="Strapline" required="false()" type="string"/>
        <!--bind id="cContentHeadline" nodeset="Images/img[@class='thumbnail']/@alt" required="false()" type="string"/-->
				<bind id="cContentThumbnail" nodeset="Images/img[@class='thumbnail']" required="false()" type="xml-replace"/>
			</bind>
			<bind nodeset="cContentXmlDetail/Content">
				<bind id="cContentHeadline" nodeset="Headline" required="true()" type="string"/>
				<bind id="dPublishDate" nodeset="PublishDate" required="false()" type="string"/>
				<bind id="cContentStrapline" nodeset="Strapline" required="false()" type="string"/>
				<bind id="cContentThumbnail" nodeset="Images/img[@class='thumbnail']" required="false()" type="xml-replace"/>	
				<bind id="cContentDetail" nodeset="Images/img[@class='display']" required="false()" type="xml-replace"/>		
				<bind id="cContentBody" nodeset="Body" required="false()" type="string"/>
			</bind>
      <bind id="dPublishDate" nodeset="dPublishDate" required="false()" type="string"/>
		</bind>
	</model>


</Content>