import {TagsField, KEventChange} from 'BobjollTagsField';
let data: string[] = ['tags-1', 'tags-2', 'tags-3'];
let field = new TagsField({
source: (q) => {
let keywords = data.reduce(function (acc, item) {
if ('' !== q) {
let search = q.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
let re = new RegExp("(" + search.split(' ').join('|') + ")", "gi");
item = item.toLowerCase();
if (item.match(re)) {
acc.push({
text: item.replace(re, '$1'),
value: item,
});
}
return acc;
}
}, []);
return keywords;
}
});
instance.addEventListener('change', function (e) {
console.log(e.extra.tag); // Added/Removed tag/tags, can be of type string or array.
console.log(e.extra.tags); // Tags array
console.log(e.extra.action); // Action add/remove
});