If your data set is large or would like to pre filter your data you can load dynamically by setting the values
to a function.
{
//..other config options
// function retrieving an array of objects
values: function (text, cb) {
remoteSearch(text, users => cb(users));
},
lookup: 'name',
fillAttr: 'name'
}
You would then define a function, in this case remoteSearch
, that returns your data from the backend.
function remoteSearch(text, cb) {
var URL = 'YOUR DATA ENDPOINT';
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
cb(data);
} else if (xhr.status === 403) {
cb([]);
}
}
};
xhr.open("GET", URL + "?q=" + text, true);
xhr.send();
}