'How to change submitLabel of TextField as the user types
I'm trying to make the submit button of a TextField to read "done" when there is no text, which would result in nothing happening, but also read "search" when there is text, which would perform a search. I tried to use a ternary operator in the .submitLabel modifier to do this, but it does not change dynamically, only when the user closes out and reopens the TextField.
TextField("Search for meals...", text: $searchText)
.submitLabel(searchText != "" ? .search : .done)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
