I am trying to have the TextField to return the value in the fly rather than the user having to pressed the return key for the value to be stored. With the current code below, the user has to press enter for value to bind with the variable. The problem is if there are multiple fields and the user just taps through them then this field will not bind. Plus the numberPad keyboard type does not have a return key.
Would appreciate the help.
struct ContentView: View {
@State var number = 0
var formatter: NumberFormatter = {
let f = NumberFormatter()
f.isLenient = true
return f
}()
var body: some View {
Form {
Section {
TextField("Price", value: $number, formatter: formatter)
.keyboardType(.numberPad)
Text("\(number)")
}
}
}
}