Overview Autocomplete
is a feature provided by many applications, and this component makes it
easy to add an autocomplete field to your form. The autocomplete
controls is not unlike an <xforms:select1> selection controls:
Modes The autocomplete can work in one of three modes, which in order of increasing complexity, are referred to as: static, resource, and dynamic.Static
<fr:autocomplete
ref="country-name" dynamic-itemset="false">Resource[NOTE: This feature was introduced after the 3.9 release, and isn't yet available in Orbeon Forms 3.9 or earlier releases.]
Dynamic
<fr:autocomplete
ref="instance('selected-countries')/dynamic"
dynamic-itemset="true">
<!-- React to user searching -->
<xforms:action ev:event="fr-search-changed">
<xxforms:variable name="search-value"
select="event('fr-search-value')"/>
<xxforms:variable name="make-suggestion"
<xforms:action if="$make-suggestion">
<!-- Update itemset -->
<xforms:setvalue ref="instance('search-dynamic')/country-name" <xforms:send
submission="update-countries"/>
</xforms:action> <xforms:action
if="not($make-suggestion)"> <!--
Delete itemset --> <xforms:delete
nodeset="instance('searched-countries')/country"/>
</xforms:action> </xforms:action>
<xforms:label>Country code: </xforms:label>
<xforms:itemset nodeset="instance('searched-countries')/country">
<xforms:label ref="name"/>
<xforms:value ref="us-code"/>
</xforms:itemset></fr:autocomplete>For more on the labelref attribute, see the above section the resource mode. Events
Setting the content of the
text fieldSetting by label You can set the content of the text field by sending
the fr-set-label event to the autocomplete component, with label
as context information. For instance:<xforms:dispatch
ev:event="DOMActivate" target="my-autocomplete" name="fr-set-label">
<xxforms:context name="label" select="'Canada'"/></xforms:dispatch>Just as if users had typed that label, if you are in dynamic itemset mode, this will trigger the fr-search-changed event,
upon which your code can change the itemset. If you do change the
itemset, and there is a single value corresponding to the label
you specified, then the node to which the autocomplete is bound is set
to that value.Setting by valueWhen using static itemset, you can set the value of the node you bind to the autocomplete control. This value can either be set initially (i.e. be present in the instance when the page is loaded), or can be set dynamically. When this happens, the autocomplete control will populate the search field with the label corresponding to that value, if there is one.Don't set the value of the node bound to an autocomplete control if you are using the dynamic or resource mode. This is because when the itemset is dynamic, you load the itemset based on the search term entered by users, responding to the fr-search-changed event. If the value is
set, the autocomplete can't dispatch a fr-search-changed
event, since it doesn't know the label yet, and your code won't load
the appropriate itemset that contains the label for the new value. In
dynamic itemset mode, always use the fr-set-label event to
indirectly set the value of the control. If you want the autocomplete to
be populated based on a value in the instance when the form loads, on xforms-model-construct-done
you need to find what the label corresponding to this value is, and
dispatch an fr-set-label event with that label. [AS OF 2011-06-02] As an exception to this rule, setting the value of bound node to empty string is supported in all cases: it is understood as a "reset" and will also set the search field to empty string.Maximum number of displayed results By
default, the autocomplete displays a maximum of 10 items. You can have
the autocomplete display less of more results by:
<fr:max-results-displayed>
element has priority over the max-results-displayed
attribute, which has priority over the global property.Displaying all the items For Orbeon Forms 3.9 [SINCE 2010-06-11]The autocomplete control shows suggestions as users start typing in the field, based on what they have already typed. What if users don't know what to start typing? This is where the show-full-itemset-dropdown="true" attribute comes into play. Add it to your <fr:autocomplete>, and you'll see a button added next to the text field:When users click on it, they will see the full list of items from which they can make a selection. Since for show-full-itemset-dropdown="true" to work, the component needs to have access to the full itemset, not just the partially loaded item load based on what users typed so far. So you can only use show-full-itemset-dropdown="true" when you are in static itemset mode.For Orbeon Forms 3.10 [SINCE 2011-06-02] By default, the autocomplete control shows a button next to the autocomplete. Clicking on the button shows the suggestions users would get if they had typed the value currently in the field. For a country list, if you have Sw in the field and you click on the button, you would get Swaziland, Sweden, and Switzerland. This won't be a common scenario as users will automatically get those suggestions when typing the Sw. A more common case is users not knowing what to type in the field. In that case they can click on the button when the field is empty, and the suggestion will contain the first n possible values. ![]() This is the out of the box behavior in static mode. It is left to you to return the first n items when in dynamic mode, when you get the fr-search-changed event with an empty label, and in resource mode when your service is called with an empty search value.You can disable this button by adding a show-suggestions-button="false" attribute on the control. The default value of this attribute is true.Styling
Possible future features |




