Skip to content

Commit

Permalink
Fix #627
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Sep 11, 2024
1 parent 820158b commit ad02561
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/sparnatural/components/widgets/AutoCompleteWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,29 @@ export class AutoCompleteWidget extends AbstractWidget {
});

// add the behavior on the input HTML element to fetch the autocompletion value
var autocompleteTimer = 0;
queryInput.addEventListener("input", (event:Event) => {
const phrase = (event.target as HTMLInputElement)?.value;
// Process inputText as you want, e.g. make an API request.

if(phrase.length >= 3) {
this.configuration.dataProvider.getAutocompleteSuggestions(
this.startClassVal.type,
this.objectPropVal.type,
this.endClassVal.type,
phrase,
callback,
errorCallback

// cancel the previously-set timer
if (autocompleteTimer) {
window.clearTimeout(autocompleteTimer);
}

autocompleteTimer = window.setTimeout(() => {
this.configuration.dataProvider.getAutocompleteSuggestions(
this.startClassVal.type,
this.objectPropVal.type,
this.endClassVal.type,
phrase,
callback,
errorCallback
)
},
350
);
}
});
Expand Down

0 comments on commit ad02561

Please sign in to comment.