forked from fillaware/integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillAwareJavaScript.js
More file actions
59 lines (46 loc) · 1.68 KB
/
Copy pathFillAwareJavaScript.js
File metadata and controls
59 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
window.addEventListener('load', function()
{
var inputName = document.getElementById('nameInput'); // nameInput is the name of input field.
inputName.addEventListener('keyup', function(event)
{
hinter(event);
});
window.suggestionReqest = new XMLHttpRequest();
});
function hinter(event)
{
if(typeof(event.key) === "undefined"
|| event.key === "Escape"
|| event.key === "ArrowRight"
|| event.key === "ArrowLeft"
|| event.key === "ArrowUp"
|| event.key === "ArrowDown")
{
return;
}
var input = event.target;
var suggestionList = document.getElementById('suggestionList'); // name of the list for suggestions
var type = event.target.getAttribute("resourceType"); // This is your attribute. resourceType can be: names, companies, first_names, last_names, emails, addresses, colors
var min_characters = 3;
var APIKey = "iSkwEtRMxzOFzWwoy8GEvsL7DMlpn94Uffrg8ETYMOlrsspEZI7Ck_ElqvevdIxz";
if (input.value.length >= min_characters)
{
window.suggestionReqest.abort();
window.suggestionReqest.onreadystatechange = function()
{
if (this.readyState === 4 && this.status === 200)
{
var response = JSON.parse(this.responseText);
suggestionList.innerHTML = '';
response.forEach(function(item)
{
var option = document.createElement('option');
option.value = item;
suggestionList.appendChild(option);
});
}
};
window.suggestionReqest.open('GET', 'https://api.fillaware.com/v1/suggest/' + type + '?q=' + input.value + "&key=" + APIKey, true);
window.suggestionReqest.send();
}
}