XForms/Entity Selection

Motivation
You want a user interface control that allows a user to select a legal entity in a contract such as a person or an organization. The list of people or organizations are supplied in a list that includes an id and a screen label. You want as-you-type functions to narrow down a list of choices from these lists.

Method
We will create a user interface control with two tabs. The first tab will be for people and the second will be for organizations.

Source Code
            Entity Selector Select either a person or an organization: Person   Organization <xf:toggle case="case-2" ev:event="DOMActivate"/> </a> <xf:switch> <xf:case id="case-1" selected="true"> <xf:input ref="Person/PersonLabel" incremental="true" class="PersonLabel" id="person-input"> <xf:label>Person: </xf:label> </xf:input> <xf:repeat nodeset="instance('candidate-people')/Person[contains(PersonLabel, instance('save-data')/Person/PersonLabel)]" id="persons-repeat"> <xf:trigger appearance="minimal"> <xf:output ref="PersonLabel"></xf:output> (<xf:output ref="PersonID"></xf:output>) <xf:action ev:event="DOMActivate"> <xf:setvalue ref="instance('save-data')/Person/PersonLabel" value="instance('candidate-people')/Person[contains(PersonLabel, instance('save-data')/Person/PersonLabel)][index('persons-repeat')]/PersonLabel" /> <xf:setvalue ref="instance('save-data')/Person/PersonID" value="instance('candidate-people')/Person[contains(PersonLabel, instance('save-data')/Person/PersonLabel)][index('persons-repeat')]/PersonID" /> </xf:action> </xf:trigger> </xf:repeat> </xf:case> <xf:case id="case-2"> <xf:input ref="Organization/OrganizationLabel" incremental="true"> <xf:label>Organization: </xf:label> </xf:input> <xf:repeat nodeset="instance('candidate-organizations')/Organization[contains(OrganizationLabel, instance('save-data')/Organization/OrganizationLabel)]" id="organizations-repeat"> <xf:trigger appearance="minimal"> <xf:output ref="OrganizationLabel"></xf:output> (<xf:output ref="OrganizationID"></xf:output>) <xf:action ev:event="DOMActivate"> <xf:setvalue ref="instance('save-data')/Organization/OrganizationLabel" value="instance('candidate-organizations')/Organization[contains(OrganizationLabel,                                    instance('save-data')/Organization/OrganizationLabel)][index('organizations-repeat')]/OrganizationLabel" /> <xf:setvalue ref="instance('save-data')/Organization/OrganizationID" value="instance('candidate-organizations')/Organization[contains(OrganizationID,                                    instance('save-data')/Organization/OrganizationID)][index('organizations-repeat')]/OrganizationID" /> </xf:action> </xf:trigger> </xf:repeat> </xf:case> </xf:switch> <xf:output ref="instance('save-data')/Person/PersonLabel"> <xf:label>Person:</xf:label> </xf:output> (<xf:output ref="instance('save-data')/Person/PersonID"/>) <xf:output ref="Organization/OrganizationLabel"> <xf:label>Organization:</xf:label> </xf:output> (<xf:output ref="instance('save-data')/Organization/OrganizationID"/>) <xf:submit submission="save"> <xf:label>Save</xf:label> </xf:submit>