Reputation: 519
I am trying to implement a send button for a chat app.
I have the following code:
TextField("Message", text: $message)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: {
self.chatModel.addMessage(message)
}) {
Text("Send")
}
Is there a way to clear the textfield when the button is pressed?
Upvotes: 1
Views: 714
Reputation: 519
I figured it out:
TextField("Message", text: $message)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: {
self.chatModel.addMessage(message)
message = ""
}) {
Text("Send")
}
Upvotes: 2