From 335c5923d6c3db297c8ac33a2bcb97c0998630fc Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 9 Sep 2024 02:32:22 +0200 Subject: [PATCH] Fixed that previous value, not current value has been taken to fetch suggestions --- .../net/codinux/banking/ui/forms/AutocompleteTextField.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt index 619d302..bf92d3d 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt @@ -43,13 +43,13 @@ fun AutocompleteTextField( val coroutineScope = rememberCoroutineScope() - fun fetchSuggestionsAsync() { + fun fetchSuggestionsAsync(query: String) { suggestionsFetchJob?.cancel() suggestionsFetchJob = coroutineScope.launch { isLoading = true - suggestions = fetchSuggestions(value) + suggestions = fetchSuggestions(query) isLoading = false if (expanded == false && suggestions.isNotEmpty()) { @@ -67,7 +67,7 @@ fun AutocompleteTextField( onEnteredTextChanged(query) if (query.length >= minTextLengthForSearch) { - fetchSuggestionsAsync() + fetchSuggestionsAsync(query) } else { suggestions = emptyList() expanded = false @@ -75,7 +75,7 @@ fun AutocompleteTextField( }, modifier = Modifier.fillMaxWidth().focusRequester(textFieldFocus).onFocusChanged { focusState -> if (focusState.isFocused && minTextLengthForSearch == 0) { - fetchSuggestionsAsync() + fetchSuggestionsAsync(value) } }, label = { Text(label) },