User:Jatin.me/SF-Defining Forms/Autocompleting on outside values

From mediawiki.org

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 method is to use External Data extension to fetch data from some external/internal source. See below for how to do this:

Autocompletion from outside URL[edit]

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:

$sfgAutocompletionURLs['URL-identifier-string'] = 'URL';

The URL in this line should look like a call to that web service, but with the substring replaced by the string "<substr>".

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

Autocompletion using External Data extension[edit]

ED supports retrieving data from a number of sources which include external URLs, regular wiki pages, uploaded files, files on the local server, databases or LDAP directories.

For autocompletion using ED you need to first call any of the parser functions of ED in the form definition (preferably at the bottom of the form definition because if you call it anywhere in between the from definition, it will create empty line spaces in the form) to fetch data from the external/internal source.See retrieving data using External Data.

This is a sample calling to #get_web_data parser function of ED to fetch data from some external/internal source:

{{#get_web_data:url=<URL>|format=csv with header|data=title_variable_name=<external_variable_name1>,image_variable_name=<external_variable_name2>, description_variable_name=<external_variable_name3>}}

Now, use the field definition as below to be able to use the values retrieved from the URL for autocompletion:

{{{field|...|values from external data=title_variable_name|image=image_variable_name|description=description_variable_name}}}