Extension:Page Forms/Autocompleting on outside values

There are two ways to have a field autocomplete on outside values - one is from a URL that takes in a substring and returns data in JSON format similar to JSON returned by MediaWiki API and the other is to use External Data extension to fetch data from some external/internal source.

Autocompletion from outside URL
To have a field autocomplete on values from outside the wiki, take the following steps:

1. Create a page/web service that takes in a substring via the query string, and displays a set of autocompletion values; the values should be in JSON format, and look like the JSON returned by the MediaWiki API (see here for an example). This also makes it easy to autocomplete on the values from another wiki.

2. Decide on a short string to represent this URL.

3. Add a line to LocalSettings.php that looks like this: The URL in this line should look like a call to that web service, but with the substring replaced by the string " ".

4. Add the parameter "values from url=URL-identifier-string" to the relevant field in the form definition.

Autocompletion using External Data extension
The External Data extension (ED) supports retrieving data from a number of sources which include external URLs, regular wiki pages, uploaded files, files on the local server, databases and LDAP directories.

To autocomplete using ED, you need to first call any of ED's "#get_..._data" parser functions within the form definition (preferably at the bottom of the form definition, to avoid unnecessary line breaks). This will fetch data that can then be used in the field tags. (See the External Data documentation for how to call these.)

Here is a sample call to #get_web_data to fetch data from some URL:

Assuming a form definition contains a call like that, a field tag can then use the values retrieved for autocompletion - not just to set the autocomplete values themselves, but also, if the input type is "combobox" or "tokens", to set a corresponding thumbnail image and description for each one. Assuming our External Data call retrieved three "columns" of values, as the one above does, the field tag using this data could look like: