Back



This example shows a single-select autocomplete with a pre-selected value using Ajax to fetch data.
Single-select (Pre-selected, Ajax)

Source of exampleCopy to clipboard


const categoryAutocomplete = new AvalynxAutocomplete('#categorySearch', {
    fetchData: async (query) => {
        const response = await fetch('php/result.php?type=categories&search=' + encodeURIComponent(query));
        return await response.json();
    },
    clearStyle: 'icon',
    onChange: (key, value) => console.log('Category:', key, value)
}, {
    placeholder: 'Search category...',
    noResults: 'No categories found'
});
	
AvalynxAutocomplete on GitHub Avalynx on GitHub