# Group Focus

Form demonstrates the observer pattern for DOMFocusIn and DOMFocusOut events. In response to the xforms-ready event a setfocus actions is fired to set the focus into the first input within 'observed Group'

| XForms 1.1 Links
Recommendation
Quick Reference

## Example

Input before observerd Group Observed Group 1 2

No control within observed group is focused

Input 1 has focus

Input 2 has focus

Input after observed Group

## XForms Markup

    <xf:model id="modelChild">
        <xf:instance>
            <data></data>
        </xf:instance>
        <xf:action ev:observer="observedGroup" ev:target="inputCase1" ev:event="DOMFocusIn">
            <xf:toggle case="c-input1"></xf:toggle>
        </xf:action>
        <xf:toggle case="c-input2" ev:observer="observedGroup" ev:target="inputCase2" ev:event="DOMFocusIn"></xf:toggle>
        <xf:toggle case="c-empty" ev:observer="observedGroup" ev:target="observedGroup" ev:event="DOMFocusOut"></xf:toggle>
    </xf:model>

    <xf:input id="input1" ref=".">
        <xf:label>Input before observerd Group</xf:label>
    </xf:input>

    <xf:group id="observedGroup" appearance="minimal">
        <xf:label>Observed Group</xf:label>
        <xf:input id="inputCase1" ref=".">
            <xf:label>1</xf:label>
        </xf:input>
        <xf:input id="inputCase2" ref=".">
            <xf:label>2</xf:label>
        </xf:input>
    </xf:group>

    <xf:switch>
        <xf:case id="c-empty">
            <p class="caseNull">No control within observed group is focused</p>
        </xf:case>
        <xf:case id="c-input1">
            <p class="caseOne">Input 1 has focus</p>
        </xf:case>
        <xf:case id="c-input2">
            <p class="caseTwo">Input 2 has focus</p>
        </xf:case>
    </xf:switch>

    <xf:input id="input2" ref=".">
        <xf:label>Input after observed Group</xf:label>
    </xf:input>

    <xf:action ev:observer="modelChild" ev:event="xforms-ready">
        <xf:setfocus control="inputCase1"></xf:setfocus>
    </xf:action>

## Limitations