Skip to content

How to change the datasource dynamically based on the value entered in the input #271

Answered by folknor
papiya130 asked this question in Q&A
Discussion options

You must be logged in to vote

q is the query as written in the input field and potentially modified by config.query for sanitization etc.

let foo = new autoComplete({
	data: {
		src: async q => {
			let data
			let url = new URL(...)
			url.searchParams.append("search", q)

			await fetch(url, stdparams)
				.then(json => (data = json))

			return data.foo
		},
		keys: ["bar", "baz"],
		cache: false
	}
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@papiya130
Comment options

Answer selected by TarekRaafat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants