Autocomplete
A search box with suggestions from another list, on a text field or a people picker. Built into Classic DFFS; set up in Custom JS. Applies to Autocomplete v1.6.56 in DFFS v4.4.5.56.
What it does
Autocomplete turns a single line of text field (or a multiple lines of plain text field, for several selections) into a search box: as the user types, it suggests matching items from another list, and can fill in other fields from the chosen item. It can also replace a people picker’s search. It runs in NewForm and EditForm, not in DispForm.
- Set it up by calling
spjs.ac.textField(…)orspjs.ac.peoplePicker(…)in the form’s Custom JS. The Autocomplete sub-tab under Plugins in the DFFS configuration only points here. - The chosen value is stored as text. Unlike a SharePoint lookup column it does not link to the source item, and it does not change if the source item changes later.
How it looks




multiselect).Autocomplete in a text field
spjs.ac.textField({
"applyTo": "Project",
"helpText": "Type a project name …",
"loadText": "",
"listGuid": "Projects",
"listBaseUrl": "/sites/pmo",
"showField": "Title",
"searchFields": [],
"filterCAML": "",
"useREST": true,
"preloadData": false,
"filterREST": "",
"optionDetailFields": ["ProjectNumber"],
"optionDetailPrefix": ["Number: "],
"enforceUniqueValues": true,
"rowLimit": 15,
"listOptionsOnFocus": false,
"minLengthBeforeSearch": 3,
"reValidateOnLoad": false,
"allowAddNew": false,
"addToFolder": null,
"isLookupInSelf": false,
"addNewAdditionalFields": [],
"multiselect": false,
"multiselectSeparator": "; ",
"orderBy": [],
"clearSetFieldsOnInvalidSelection": false,
"setFields": [{ "fromFIN": ["ProjectNumber"], "joinBy": "", "toFIN": "ProjectNo", "parseFunction": "", "skipIfEmpty": false }],
"debug": false
});
Text field options
| Option | Type | What it does |
|---|---|---|
applyTo | string | The FieldInternalName of the field to add autocomplete to. |
helpText | string | Placeholder text in the empty field. |
loadText | string | Text shown while a large REST data set loads (with several searchFields). |
listGuid | string | GUID or display name of the source list. Use the GUID if list names are translated. A list’s GUID is _spPageContextInfo.pageListId in the browser console on one of its views. |
listBaseUrl | string | Server-relative URL of the source list’s site, for example "/sites/pmo"; "" for the root site (_spPageContextInfo.webServerRelativeUrl in the console). |
showField | string | The field shown and searched. To search on two values (name and number), make a calculated column that joins them, or use searchFields. |
searchFields | array | More fields to search in, while still showing showField. |
filterCAML | string | A CAML condition that limits the source items, for example the current user’s items: <Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Integer'><UserID/></Value></Eq>. {function:myFilter} calls a function in Custom JS for each search; it must return the CAML. |
useREST | boolean | Query the list with REST, without blocking the page. |
preloadData | boolean | With useREST: load all items once for faster searching. The search then also understands "exact text" in double quotes, and OR (upper case) between words; otherwise words separated by spaces must all match. |
filterREST | string | A REST filter that limits the source items, for example startswith(Title,'t'). {function:myFilter} works as for filterCAML. |
optionDetailFields | array | Extra fields shown with each suggestion to help pick the right item. They are not saved; use setFields to copy them into the form. |
optionDetailPrefix | array | Labels for optionDetailFields, one per field, for example ["Number: ", "Owner: "]. |
enforceUniqueValues | boolean | Show each value only once. |
rowLimit | number | The most suggestions to fetch; keep it low for speed. |
listOptionsOnFocus | boolean | Show suggestions as soon as the field gets focus, like a dropdown with an arrow. |
minLengthBeforeSearch | number | How many characters before the search starts. |
reValidateOnLoad | boolean | In EditForm, check that the saved value still matches exactly one source item (not with multiselect). A value whose item was deleted, or that matches several items, shows as invalid. |
allowAddNew | boolean | Offer to add a typed value that matches nothing to the source list. When isLookupInSelf is false, listGuid must be the list’s GUID. |
addToFolder | object or null | With allowAddNew (not in self): add new items to a folder, created if missing: {"rootFolder": "/sites/pmo/Lists/Projects", "folderName": "Folder A"}. |
isLookupInSelf | boolean | true when the source list is the form’s own list (used with allowAddNew). |
addNewAdditionalFields | array | With allowAddNew: copy form fields into the new source item, [{"fromFIN": "ProjectNumber", "toFIN": "PNumber"}]. |
multiselect | boolean | Let users choose several items (use a multiple lines of plain text field). setFields cannot be used with it. |
multiselectSeparator | string | What separates the choices in the stored text; "; " by default. |
orderBy | array | Sort order, for example [{"fin": "Created", "ascending": true, "numeric": false, "parseFunction": ""}]. numeric sorts numbers as numbers. parseFunction names a function in Custom JS that turns each value into something sortable; it receives the value. |
clearSetFieldsOnInvalidSelection | boolean | Clear the setFields fields when the user leaves the field without a valid choice. |
setFields | array | Fill in other form fields from the chosen item (below). |
debug | boolean | Show debug information while you set it up. |
setFields
Each entry copies from the chosen source item into a form field:
fromFIN: array of source fields; several are joined into one value withjoinBy("<br>"for a rich text field,"\n"for plain text).toFIN: the form field to fill in.parseFunction: name of a function in Custom JS that receives the value and thetoFINfield name and returns the value to set.skipIfEmpty: leave the form field alone when the source value is empty.
// Custom JS: turn a source date into [date, hour, minute] for a date field.
// Write the date in the form's own date format (here MM/dd/yyyy).
function toFormDate(value, fin) {
var d = new Date(value);
return [spjs.dffs.formatDate(d, "MM/dd/yyyy"), d.getHours(), d.getMinutes()];
}
Autocomplete in a people picker
SharePoint 2013 and later already have a searching people picker, so this is off there unless you set forceOn2013. It works on single-person fields only.
spjs.ac.peoplePicker({
"applyTo": "Responsible",
"forceOn2013": true,
"helpText": "Enter name or e-mail …",
"showField": "Title",
"enforceUniqueValues": true,
"chooseFromUserGroup": "",
"showUsersOnly": true,
"rowLimit": 5,
"listOptionsOnFocus": false,
"reValidateOnLoad": false,
"setFields": []
});
People picker options
The options shared with the text field work as described above.
| Option | What it does |
|---|---|
forceOn2013 | true to use this autocomplete on SharePoint 2013 and later. |
chooseFromUserGroup | Only suggest members of this SharePoint group (name, or ID as a number), or of several groups in an array; empty for all users. If the people column itself is limited to a group in the list settings, use the same group here. |
showUsersOnly | Suggest users only, not groups. |
Change the texts
Set this in Custom JS before calling spjs.ac.textField or spjs.ac.peoplePicker:
spjs.ac.text = {
"noItems": "No items match your search",
"addNewItem": "Add {0} to the list?",
"noValidItems": "No valid items match your search",
"invalid": "Invalid value",
"moreItemsLabel": "Showing the first {0} items",
"moreItemsMouseover": "Continue typing to narrow your search",
"searching": "Searching for: "
};
From code
spjs.ac.destroy("Project")removes the autocomplete from a field.spjs.ac.setFieldValue("Project", "Project X")sets the value.
Callbacks. Define these in Custom JS to react when the user makes a valid choice, leaves an invalid value, or clears the field:
function spjs_ac_validSelectionCallback(fin, value) { }
function spjs_ac_invalidSelectionCallback(fin, value) { }
function spjs_ac_clearSelectionCallback(fin) { }
Filtering large lists
For a source list over 5,000 items that you cannot filter in the query, load everything ("useREST": true, "preloadData": true) and filter afterwards:
loadAdditionalFields: extra data to load for the filter, for example{"select": ["Author/Id"], "expand": ["Author"]}.postPreloadFilterFn: a function that receives each item and returnstrueto keep it.
"postPreloadFilterFn": function (item) {
return item.Author.Id === _spPageContextInfo.userId;
}