Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
fix(query): the query attribute should reflect the original query
Browse files Browse the repository at this point in the history
With the previous code, the `query` attribute was set to the input value
AFTER it has been updated.
  • Loading branch information
redox committed Apr 28, 2016
1 parent b73119f commit f02f766
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/formatHit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import findType from './findType.js';
export default function formatHit({
hit,
hitIndex,
query,
templates
}) {
try {
Expand Down Expand Up @@ -36,6 +37,7 @@ export default function formatHit({
return {
...suggestion,
value,
_query: query,
_dropdownValue: dropdownValue,
_index: hitIndex
};
Expand Down
16 changes: 9 additions & 7 deletions src/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import pinIcon from './icons/address.svg';

const filterSuggestionData = suggestion => ({
...suggestion,
// omit _dropdownValue and _index,
// omit _dropdownValue, _index and _query,
// _dropdownValue is not needed user side
// _index is sent at the root of the element
// _index & _query are sent at the root of the element
_dropdownValue: undefined,
_index: undefined
_index: undefined,
_query: undefined
});

export default function places({
Expand Down Expand Up @@ -79,14 +80,15 @@ export default function places({
formatHit({
hit,
hitIndex,
query,
templates
})
)
)
.then(suggestions => {
placesInstance.emit('suggestions', {
suggestions: suggestions.map(filterSuggestionData),
query: autocompleteInstance.val()
query,
suggestions: suggestions.map(filterSuggestionData)
});
return suggestions;
})
Expand All @@ -107,15 +109,15 @@ export default function places({
autocompleteInstance.on(`autocomplete:${eventName}`, (_, suggestion) => {
placesInstance.emit('change', {
suggestion: filterSuggestionData(suggestion),
query: autocompleteInstance.val(),
query: suggestion._query,
suggestionIndex: suggestion._index
});
});
});
autocompleteInstance.on('autocomplete:cursorchanged', (_, suggestion) => {
placesInstance.emit('cursorchanged', {
suggestion: filterSuggestionData(suggestion),
query: autocompleteInstance.val(),
query: suggestion._query,
suggestionIndex: suggestion._index
});
});
Expand Down

0 comments on commit f02f766

Please sign in to comment.