You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i'm trying to add a sort of "debounce" behaviour to trigger the autocomplete functionality only some time after the user has stopped typing because to retrieve the autocomplete suggestion i'm calling an external service (simple wrapper around google maps geolocation api) and the default autocomplete behaviour causes that for every single letter typed a call is made to the external service leading to the application using too much resources.
The problem is that if i set the autocomplete options after the suggestion list is opened the list is not refreshed until i type another character (space). My code uses spring reactor to implement the debounce behavior (it is in groovy, i hope it is sufficiently clear):
privateAutocomplete autocomplete =newAutocomplete(5)
privateFlux<String> userInputs
privateMap<String, GeocodingResult> tempResults
privateGeocodingResult selectedAddress
...
@PostConstructdefinit() {
userInputs =Flux.create { emitter->
autocomplete.addChangeListener {
emitter.next(it.value)
}
}
userInputs.sampleTimeout { Mono.delay(Duration.ofSeconds(2)) } //debounce 2 seconds after user ends typing
.filter { it.length() >4 } //filter only strings of 5 characters or more
.map { googleMaps.search(it) }
.subscribe { GeocodingResult[] results->
tempResults = results.collectEntries {result-> [result.formattedAddress, result] } //map by formatted address
onUI {
autocomplete.options = tempResults.keySet().toList() //use formatted addresses as suggestion list
}
}
autocomplete.addAutocompleteValueAppliedListener {
selectedAddress = tempResults[it.value] //store selected address for further use
}
}
staticvoidonUI(Componentcomponent, Commandcommand) {
component.UI.ifPresent{it.access(command)}
}
It almost works but when i have the suggestion list opened, change some text and wait 2 seconds the new suggestions are retrieved but they are not shown until i type something else (space, comma...)
Is there a way to force the suggestions list refresh when i set the options? Or better, is there a way to have the autocomplete field trigger autocompletion only for string over a certain length and automatically debounce suggestions retrieval?
The text was updated successfully, but these errors were encountered:
Hi, i'm trying to add a sort of "debounce" behaviour to trigger the autocomplete functionality only some time after the user has stopped typing because to retrieve the autocomplete suggestion i'm calling an external service (simple wrapper around google maps geolocation api) and the default autocomplete behaviour causes that for every single letter typed a call is made to the external service leading to the application using too much resources.
The problem is that if i set the autocomplete options after the suggestion list is opened the list is not refreshed until i type another character (space). My code uses spring reactor to implement the debounce behavior (it is in groovy, i hope it is sufficiently clear):
It almost works but when i have the suggestion list opened, change some text and wait 2 seconds the new suggestions are retrieved but they are not shown until i type something else (space, comma...)
Is there a way to force the suggestions list refresh when i set the options? Or better, is there a way to have the autocomplete field trigger autocompletion only for string over a certain length and automatically debounce suggestions retrieval?
The text was updated successfully, but these errors were encountered: