To set the TextField back to the initial prompt text, you can reset the value of the TextField to an empty string by setting it to an empty string literal, like this:
TextField("Enter your name", text: $name)
Button("Reset") {
name = ""
}
In this example, we create a TextField with a prompt text "Enter your name" and bind its value to a @State variable named name
. We also create a Reset button that when tapped, sets the value of the name
variable to an empty string, thus resetting the TextField back to its initial prompt text.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-07-29 11:00:00 +0000
Seen: 8 times
Last updated: Oct 27 '21
How can I make the Vuetify Combobox return the id instead of the value?
How can wrapping be turned off in a textarea?
How can I display only the name and hide the button and text input box?
How can I load a text file in gensim?
How can I indent numerous lines of the HTML tag <p>?
How can I change the name of a subfolder within multiple folders by replacing a portion of the text?
How to arrange columns in a Flutter datatable?
How can I use html-React to substitute specific text within a contentEditable div?
How can the text size of the plot be enlarged using ggcuminc?