How can I implement an input field with word prediction without using scafolding or SILKUI Select2?
For example: I have a search field where I want to choose a user; I want to dynamically query the database while I type and to be presented with a list of suggestions. Since I have a big list of users I would prefer to avoid using Select2 which has to return all of my users to populate a Combo Box or List Box before being able to start the client-side filtering.
To create a search field with autocomplete follow these steps:
Variableproperties of the search field Input Widget to a Local Variable (in this case
Add an Input_AutoComplete RichWidget next to the Input Widget and set the
InputWidgetIdproperty to the Id of the Input.
Destinationproperty of Input_AutoComplete to a newly created Screen Action, in this case UsersAutoComplete.
Add an Aggregate to the Screen Action and create a Filter using the Local Variable to limit the query results according to what is typed in the Input.
In this case the Filter
Users.Name like "%"+Name_Search+"%"only retrieves users whose
NameAttribute includes what is typed in the Input.
Add an Input_AutoComplete_ShowList Server Action after the Aggregate.
InputWidgetIdproperty to the Id of the Input and the
Listto the Aggregate's List, in this case
Be sure to map the
Labelholds the value displayed in the autocomplete list and the
Identifierholds the Identifier of those values.
The Screen Action will look similar to the following image:
The action queries the database for the autocomplete suggestions that appear below the Input field.
After these steps the search field now shows a list of suggestions that changes as you type:
To access the Identifier of the selected user use the Input_AutoComplete_GetIdentifier Server Action.