Autosuggestions
Contents
See Also
Advanced Canvas Control Attributes, ALTER TABLE, Autosuggestions Column Constraint, Autosuggestionheaders Column Constraint, Choices, Constraints, CREATE TABLE, Data Attributes, Data Mapping, Field Attributes, FIELDAUTOSUGGESTIONS(), FIELDAUTOSUGGESTIONHEADERS(), FIELDCHOICES(), GETDATAMAPPING(), Help Attributes, SQL SELECT, SETDATAMAPPING(), SQLVALUES(), Working with the Lianja Object Model
Overview
Autosuggestions provide filtered choices as the user types in a Form or Canvas Section field.
The choices are displayed in a dropdown under the control. Clicking on a choice loads its value into the field.
Autosuggestions can be:
- Static list with or without a dropdown (autocomplete)
- Dynamic table-based list
- SQL Select based list
- User defined function based list
Autosuggestions are defined by the following field attributes found in the Data sub-section of the attributes dialog:
Attribute | Description |
---|---|
Autosuggestions | The list of Autosuggestions values to display as the user types |
Autosuggestion headers | A comma separated list of column headers to display for the Autosuggestions |
Autosuggestion column to search | The column to search for Autosuggestions |
Autosuggestions can also be defined in the data dictionary using the following Field attributes (Create/Modify Column):
Attribute | Description |
---|---|
Autosuggestions | The list of Autosuggestions values to display as the user types |
Autosuggestion headers | A comma separated list of column headers to display for the Autosuggestions |
When defined in the data dictionary, SQL Select based Autosuggestions are also supported in the Web client, see Web Client below.
Static Lists
Static lists are based on a comma-separated list of choices specified in the Autosuggestions attribute.
Autosuggestions: Buchanan,Callahan,Davolio,Dodsworth,Fuller,King,Leverling,Peacock,Suyama
With a standard static list, the dropdown is displayed as the user types, showing filtered values based on the input.
Typing 'd' displays all the values from the list starting with 'd' or 'D'.
Prefixing the list with '-' does not display the dropdown. Instead, it operates as an autocomplete.
Autosuggestions: -Buchanan,Callahan,Davolio,Dodsworth,Fuller,King,Leverling,Peacock,Suyama
Typing 'd' autocompletes with the first value in the list starting with 'd' or 'D'.
Dynamic List
A dynamic list is based on the evaluation of an expression from a specified table.
@<table-name>,<expression>
Here the list is based on the current values of the lastname field from the employees table.
Autosuggestions: @employees,lastname
The dropdown displays filtered values from the table.
SQL Select Lists
SQL Select lists are generated by the resultset from a SQL Select statement.
Here the list is based on the current values of the lastname field from the employees table.
Autosuggestions: select lastname from employees
The dropdown displays filtered values from the resultset.
The SQL Select statement can reference more than one column.
Autosuggestions: select lastname, firstname from employees
By default, the first column, lastname, is the search column.
Clicking on a choice will load the value of the search column into the field.
For multi-column SQL Select lists, the Autosuggestion headers attribute can be used to specify a comma separated list of column headers for the dropdown.
Autosuggestions: select lastname, firstname from employees
Autosuggestion headers: Surname,Firstname
The dropdown is displayed with column headers.
For multi-column SQL Select lists, the Autosuggestion column to search attribute can be used to specify the column to search.
Columns are numbered from 0. Here the lastname column is the search column.
Autosuggestions: select firstname, lastname from employees
Autosuggestion headers: Firstname,Surname
Autosuggestion column to search: 1
The second column is the search column.
Clicking on a choice will load the value of the search column into the field.
Web Client
SQL Select based autosuggestions are supported in the Web client provided that they are set in the data dictionary and the section has the Inherit dictionary rules Attribute set to True.
Note that the Formitem does not allow free entry if Autosuggestions are set, only a selection from the list.
Autosuggestions: select distinct contacttitle,contactname from customers
Autosuggestion headers: Title,Name
Note: 'Autosuggestion column to search' is not currently supported in the data dictionary and Web Client.
Setting the Inherit dictionary rules Section Attribute for the Form Section to True causes the data dictionary settings to be applied to the Formitem Attributes automatically.
Remember the database needs to be deployed after making any data dictionary changes, before these will be available in the desktop App Center or Web/Mobile client.
With the Section Inherit dictionary rules Attribute set to True, changes you make to Formitem Attributes in Form or Canvas Sections will be overwritten by their data dictionary equivalents, if set, when the App is saved and reloaded.
User Defined Function
The Autosuggestions list can be based on the return value from a user defined function or procedure (Lianja/VFP scripting).
"{UserDefinedFunction()}"
The return value should be a comma-separated list. Here the list is based on the return value from the 'getempname' procedure defined in the App's custom library.
Autosuggestions: "{getempname()}"
As in the other examples, it returns the lastname field values from the employees table.
proc getempname() sqlvalues("select lastname from employees order by lastname") creturn = astring(_sqlvalues) return creturn endproc
The dropdown displays filtered values from the list returned by the procedure.
Notes on Client Support
Attribute | Notes |
---|---|
Autosuggestions | Desktop client and Web client. Supported in Web client when defined in the data dictionary, see Web Client above. |
Autosuggestion headers | Desktop client and Web client. Supported in Web client when defined in the data dictionary, see Web Client above. |
Autosuggestion column to search | Currently supported on the Desktop client only. |
Notes on Scripting Support
- The Autosuggestions attribute can be queried or changed programmatically in Lianja/VFP scripting using Lianja.getElementByID("page.section.field").autosuggest.
- The Autosuggestion Headers attribute can be queried or changed programmatically in Lianja/VFP scripting using Lianja.getElementByID("page.section.field").autosuggestheaders.
- Autosuggestions functionality is also available in the Textbox framework class control for VFP Custom Sections.
- The CREATE TABLE and ALTER TABLE commands can also be used to set or modify data dictionary Field attributes (Column Constraints).
- The Autosuggestions data dictionary Field attribute (Autosuggestions Column Constraint) can be queried using the FIELDAUTOSUGGESTIONS() function.
- The Autosuggestion headers data dictionary Field attribute (Autosuggestionheaders Column Constraint) can be queried using the FIELDAUTOSUGGESTIONHEADERS() function.