Skip to content

I can't change the data list at run time #305

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

You must be logged in to vote

So you are creating a new autoComplete instance every time the radio selection changes? That's a bad idea. Do this instead:

	const autoCompleteJS = new autoComplete({
		placeHolder: "Cerca una categoria...",
		data: {
			src: function (query) {
				if (document.querySelector('input[name="sel-tipo-annuncio"]:checked').value == 'Bene') {
					return passedArrayBene.slice();
				}
				else {
					return passedArrayServizio.slice();
				}
			}
		},
		resultItem: {
			highlight: false
		},
		events: {
			input: {
				selection: (event) => {
					const selection = event.detail.selection.value;
					autoCompleteJS.input.value = selection;
				}
			}
		}
	});

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@adilorenzo10
Comment options

@folknor
Comment options

@ashinsaini
Comment options

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