Is it possible to submit a TextField when using the numberPad?
Or configuer a keyboard toolbar button to submit?
TextField("Enter your answer here", text: $answer)
.keyboardType(.numberPad)
.focused($isFocused)
I have added a button to keyboard toolbar which removes focus but doesn't submit.
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") {
isFocused = false
}
}
}
I tried adding return after removing the focus but it was no different.
I have an onSubmit() action which works when pressing enter on a physical keyboard, but not using the "Done" button.
.onSubmit() {
showingAlert = checkAnswer(answer: Int(answer) ?? 0)
}
If I comment out the .keyboardType and use the standard keyboard which has the return button, the code works as expected and I can even change this button using .submitLabel(.done) but obviously this doen't apply to the .numberPad keyboard type.
I know I can run a function on the button press using action: but this is not the way I wanted to go.
I hope the above makes sence and thank you for reading