<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="test.css" ?>
<!DOCTYPE html [
	<!ATTLIST section id ID #IMPLIED>
	<!ATTLIST h       id ID #IMPLIED>
	<!ATTLIST div     id ID #IMPLIED>
	<!ATTLIST nl      id ID #IMPLIED>

  <!-- for the model attribute to work -->
  <!ATTLIST xforms:model id ID #IMPLIED>

  <!-- for the bind attribute to work -->
  <!ATTLIST xforms:bind id ID #IMPLIED>

  <!-- for the instance() function to work -->
  <!ATTLIST xforms:instance id ID #IMPLIED>

  <!-- for submit to work -->
  <!ATTLIST xforms:submission id ID #IMPLIED>

  <!-- for setfocus and other events to work -->
  <!ATTLIST xforms:input id ID #IMPLIED>
  <!ATTLIST xforms:secret id ID #IMPLIED>
  <!ATTLIST xforms:textarea id ID #IMPLIED>
  <!ATTLIST xforms:output id ID #IMPLIED>
  <!ATTLIST xforms:upload id ID #IMPLIED>
  <!ATTLIST xforms:range id ID #IMPLIED>
  <!ATTLIST xforms:trigger id ID #IMPLIED>
  <!ATTLIST xforms:submit id ID #IMPLIED>
  <!ATTLIST xforms:select id ID #IMPLIED>
  <!ATTLIST xforms:select1 id ID #IMPLIED>

  <!-- for toggle to work -->
  <!ATTLIST xforms:case id ID #IMPLIED>

  <!-- for repeat stuff to work -->
  <!ATTLIST xforms:repeat id ID #IMPLIED>

  <!-- (also any element with xforms:repeat-* attributes -->
 	<!ATTLIST table      id ID #IMPLIED>
  <!ATTLIST td         id ID #IMPLIED>
]>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xml:lang="en">
  <head>
    <title>4.3.2 xforms-focus Event</title>

    <xforms:model>

		
    	<xforms:instance>
    		<instance xmlns="">
    			<a>a</a>
    			<b>b</b>
    			<focuscount>0</focuscount>
    		</instance>
    	</xforms:instance>
	</xforms:model>

  </head>
  <body>
    <h>xforms-focus</h>
    <p>Assertions tested by this test case:</p>
    <nl>
        <li>Assertion 4.3.2-1</li>
        <li>Assertion 4.3.2-2</li>
    </nl>	
    <p>
		If a form control can hold focus, focus is transferred to it, otherwise nothing happens. 
		If xforms-focus is dispatched to a group, repeat, switch or case the first child in navigation order receives focus.
		success: focuscount = 3
    </p>
    
    <xforms:input ref="a" id="input1">
		<xforms:label>label 1</xforms:label>
		<xforms:action ev:event="DOMFocusIn">
			<xforms:setvalue ref="/instance/focuscount" value="/instance/focuscount + 1"/>
			<xforms:dispatch name="xforms-focus" target="group1" ev:event="xforms-activate"/>
		</xforms:action>
	</xforms:input>
    
	<xforms:group id="group1">
		<xforms:input ref="a" id="input2">
			<xforms:label>label 2</xforms:label>
			<xforms:action ev:event="DOMFocusIn">
				<xforms:setvalue ref="/instance/focuscount" value="/instance/focuscount + 1"/>
				<xforms:dispatch name="xforms-focus" target="repeat1" ev:event="xforms-activate"/>
			</xforms:action>
	
		</xforms:input>
	</xforms:group>

	<xforms:repeat nodeset="b" id="repeat1">
		<xforms:input ref="." id="input3">
			<xforms:label>label 3</xforms:label>
			<xforms:action ev:event="DOMFocusIn">
				<xforms:setvalue ref="/instance/focuscount" value="/instance/focuscount + 1"/>
				<xforms:dispatch name="xforms-focus" target="input4" ev:event="xforms-activate"/>
			</xforms:action>
			
		</xforms:input>		
	</xforms:repeat>

	<!-- control disabled because c does not exists. Thus the control is unable to receive focus. -->
	<xforms:input ref="c" id="input4">
		<xforms:label>label 4</xforms:label>
		<xforms:action ev:event="DOMFocusIn">
			<xforms:setvalue ref="/instance/focuscount" value="/instance/focuscount + 1"/>
		</xforms:action>			
	</xforms:input>		

	<xforms:output ref="focuscount"/>	
	<xforms:trigger>
		<xforms:label>start</xforms:label>
		<xforms:action ev:event="xforms-activate">
			<xforms:setvalue ref="focuscount">0</xforms:setvalue>
			<xforms:dispatch name="xforms-focus" target="input1" />
		</xforms:action>
	</xforms:trigger>
  </body>
</html>
