Home > Software design >  TextField typing not completing
TextField typing not completing

Time:01-02

I have a Form and TextField input that should update a variable in a separate view model with that text input.

The problem is that the first letter appears in the field fine, but when I click the next letter it deletes the first letter. Then when I click a letter again, nothing happens. Then I click a letter again and the same thing starts from the beginning.

Thanks for your help!

struct FormView: View {
    @StateObject var listVM = ListVM()
    
    var body: some View {
        NavigationView {
            VStack {
                Form {
                    TextField("Summary", text: $listVM.textInput)
                }

                Button {
                } label: {
                    HStack {
                        Image(systemName: "plus.circle.fill")
                        Text("Add summary").fontWeight(.bold)
                    }
                }.buttonStyle(.borderedProminent)
                    .padding(.top)
                    .tint(.indigo)
            }.navigationTitle("Create summary")
            
        }
        
    }
}

class ListVM: ObservableObject {
    @State var textInput = ""
}

CodePudding user response:

@State is only for SwiftUI Views you should be using @Published

@Published var textInput = ""
  • Related