autocomplete:selected on v1 #637
-
Question 1Before v1, we had to listen for the I've read this but I can't understand a damn thing. I don't use JSX, I write plain JavaScript. pre-v1 configuration: ]).on('autocomplete:selected', function(event, suggestion, dataset, context) {
hiddenInput.value = suggestion.id;
}); v1-configuration: autocomplete({
container: '#autocompletarProcesso',
placeholder: 'Pesquise por processos',
getSources({setQuery, query}) {
return [{
sourceId: 'processos',
getItems() {
return [{id: 1, nome: 'processo 1'}, {id: 2, nome: 'processo 2'}];
},
templates: {
item({item}) {
return item.nome;
},
noResults() {
return 'Nada encontrado';
}
}
}];
}
}); Question 2When I select one of the suggestions (by keyboard or mouse), the input doesn't replace the query with the selected value. What am I missing? Example:
Expected search box value: "processo 1" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
onSelect() and setQuery() are what I was looking for. Such basic things buried so deep in the docs. autocomplete({
container: '#autocompletarProcesso',
placeholder: 'Pesquise por processos',
getSources({setQuery, query}) {
return [{
sourceId: 'processos',
onSelect({item}) {
setQuery(item.nome);
// do anything else
},
getItems() {
return [{id: 1, nome: 'processo 1'}, {id: 2, nome: 'processo 2'}];
},
templates: {
item({item}) {
return item.nome;
},
noResults() {
return 'Nada encontrado';
}
}
}];
}
}); |
Beta Was this translation helpful? Give feedback.
onSelect() and setQuery() are what I was looking for.
Such basic things buried so deep in the docs.