OnChange() doesn't trigger inside picker navigation view

For some reason the on change that I put on textfield only triggered after I close the selection view.
Picker("Game", selection: $selectedGame) {
Text("No Game Selected").tag(0 as Int?)
Section{
TextField("Search Here", text: $gv.searchTerm).onChange(of: gv.searchTerm) { newValue in
print("On Change Triggered")
searchTimer?.invalidate()
searchTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { _ in
Task{

try await gv.fetchGames(searchQuery: newValue)

}
}
}
}


ForEach(gv.games, id: \.self) { game in
Text(game.name).tag(game.id as Int?)
}
}
.pickerStyle(.navigationLink)

}
Picker("Game", selection: $selectedGame) {
Text("No Game Selected").tag(0 as Int?)
Section{
TextField("Search Here", text: $gv.searchTerm).onChange(of: gv.searchTerm) { newValue in
print("On Change Triggered")
searchTimer?.invalidate()
searchTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { _ in
Task{

try await gv.fetchGames(searchQuery: newValue)

}
}
}
}


ForEach(gv.games, id: \.self) { game in
Text(game.name).tag(game.id as Int?)
}
}
.pickerStyle(.navigationLink)

}
2 Replies
outsharded
outsharded14mo ago
Are you sure on change is for changes to a selection? If it triggers from a closure, maybe that’s what it’s meant to do Have a look through docs
ellocomen
ellocomen14mo ago
Can you send full code?
Want results from more Discord servers?
Add your server