Back
This example shows a multi-select autocomplete with tags positioned inline and a clear icon using Ajax to fetch data.
const languageAutocomplete = new AvalynxAutocomplete('#languageSearch', {
fetchData: async (query) => {
const response = await fetch('php/result.php?type=languages&search=' + encodeURIComponent(query));
return await response.json();
},
maxSelections: 5,
tagsPosition: 'inline',
clearStyle: 'icon',
defaultSelections: [
{ key: 'LNG001', value: 'German' },
{ key: 'LNG002', value: 'English' }
],
onChange: (keys, values) => console.log('Languages:', keys, values)
}, {
placeholder: 'Add languages (max. 5)...',
noResults: 'No languages found',
removeTitle: 'Remove'
});
AvalynxAutocomplete on GitHub Avalynx on GitHub