tagger
tagger copied to clipboard
Add more documentation about completion/link/filter to README
I want to use a tagging component for adding keywords to an item. There can be thousands of keywords, so I want to have:
- the user start typing a matching keyword
- perform a query, using the currently typed match, to a web server after a short delay
- get a json response with suitable matches
- allow the user to choose a match
Thanks.
Look at the signature of completion:
completion {list: string[] | function(): Promise(string[])|string[], delay: miliseconds, min_length: number}
This is pseudo TypeScript.
You can use:
var tags = tagger(input, {
completion: {
list(str) {
return fetch(`/api/completion?text=${str}`).then(res => res.json());
},
delay: 500,
min_length: 2
}
});
There is only missing argument to the function in README.
I've added some documentation to the demo. There is also a need to add some docs to README.
Typescript signatures aren't my thing. I assume the signature should be interpreted as: a function that takes (a currently undocumented) string argument and returns either a Promise that resolves to a list/array of strings, or returns a list/array of strings directly. Am I interpreting that correctly?
In my case I guess I would need to create a new Promise that wraps the fetch and changes the shape of res.json to return a list of strings as the returned value from the search (for first) looks like:
{
"data": {
"collection": [
{
"id": "3",
"link": "https://endpoint.example.com/ep/rest/data/keyword/3",
"name": "First Time Failure"
}
],
"@total_size": 1
}
}
Yes, exactly.