Wiki

Clone wiki

javarosa / TrainingForm8

<h:html xmlns="http://www.w3.org/2002/xforms"
        xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:jr="http://openrosa.org/javarosa">
	<h:head>
		<h:title>Demo Form</h:title>

		<model>
			<instance>
				<!-- the XML inside here is what gets filled out and submitted when you complete the form -->
				<student>
					<form_version>0.0.2</form_version>
					<name />
					<city>DAR ES SALAAM</city>
					<sex />
					<pregnant />
					<age />
					<grad_date />
					<interests />
					<music_type />
					<tupac/>
					<certifications />
				</student>
			</instance>

			<!-- binds allow us to add properties to the questions, like data types, skip logic, etc.-->
			<bind nodeset="name" required="true()" /> 
			<bind nodeset="pregnant" relevant="../sex='f'" />
			<bind nodeset="age" type="int" constraint=". &lt; 120" jr:constraintMsg="Age cannot be above 120!" />
			<bind nodeset="grad_date" type="date" constraint=". &gt; today()" jr:constraintMsg="Graduation day must be in the future!" />
			<bind nodeset="music_type" relevant="selected(../interests, 'music')" />
			<bind nodeset="tupac" relevant="selected(../interests, 'music')" />
			<bind nodeset="certifications" constraint="not(selected(., 'unknown') and count-selected(.) &gt; 1)" jr:constraintMsg="'Don't know' can't be chosen in combination with other certifications" />
		</model>
	</h:head>

	<h:body>
		<!-- This is where we define the questions that the user will fill out -->
		<input ref="name">
			<label>What is your name?</label>
		</input>

		<input ref="city">
			<label>What city do you live in?</label>
		</input>
		
		<select1 ref="sex">
			<label>Are you male or female?</label>
			<item>
				<label>Male</label>
				<value>m</value>
			</item>
			<item>
				<label>Female</label>
				<value>f</value>
			</item>
		</select1>
		
		<select1 ref="pregnant">
			<label>Are you pregnant?</label>
			<item>
				<label>Yes</label>
				<value>y</value>
			</item>
			<item>
				<label>No</label>
				<value>n</value>
			</item>
		</select1>
		
		<input ref="age">
			<label>How old are you?</label>
		</input>

		<input ref="grad_date">
			<label>When will you graduate?</label>
		</input>
		
		<select ref="interests">
			<label>What are your interests?</label>

			<item>
				<label>Eating Ugali</label>
				<value>ugali</value>
			</item>
			<item>
				<label>Watching TV</label>
				<value>tv</value>
			</item>
			<item>
				<label>Music</label>
				<value>music</value>
			</item>
			<item>
				<label>Making XForms</label>
				<value>xforms</value>
			</item>
		</select>
		
		<select ref="music_type">
			<label>What type of music do you like?</label>

			<item>
				<label>Bongo flava</label>
				<value>bongo</value>
			</item>
			<item>
				<label>Michael Bolton</label>
				<value>mb</value>
			</item>
			<item>
				<label>Michael Jackson</label>
				<value>mj</value>
			</item>
		</select>

		<select1 ref="tupac">
			<label>Do you also like Tupac?</label>
			<item>
				<label>Yes</label>
				<value>y</value>
			</item>
			<item>
				<label>No</label>
				<value>n</value>
			</item>
		</select1>
		
		<select ref="certifications">
			<label>What are your certifications?</label>

			<item>
				<label>XForm Fundi</label>
				<value>xform_fundi</value>
			</item>
			<item>
				<label>TSO</label>
				<value>tso</value>
			</item>
			<item>
				<label>CBEX</label>
				<value>cbex</value>
			</item>
			<item>
				<label>Don't know</label>
				<value>unknown</value>
			</item>
		</select>
		
	</h:body>
</h:html>

Updated