I am trying to add an icon ( SFSymbol) called "exclamationmark.triangle" if the field is empty to identify that it's a required text field. Below is the method I used. It works, but not properly. When the user clicks on a text field and starts typing after the first character keyboard goes away, so the user has to retap to continue typing.
if name.isEmpty {
HStack {
TextField("First & Last Name", text: $name)
Image(systemName: "exclamationmark.triangle")
}
} else {
TextField("First & Last Name", text: $name)
}