0

I have a form with some of the textfields using the default keyboard. In the example below, the first textfield is using numberPad, and the second and third are using the default keyboard. When I try to input any value in the first field, it works fine. But after moving to the second field, the keyboard suddenly dismisses after clicking the first character.

enter image description here

import SwiftUI

struct SettingsForm: View {
    @ObservedObject var model : SettingModel
    
    var body: some View {
        Form {          
            Section {
                TextField("Title", text: $model.title)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8)
                    .keyboardType(.numberPad)
                TextField("Request Signal", text: $model.signal)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8.0)
                TextField("Message", text: $model.message)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8.0)
            } header: {
                Text("DETAILS")
            } footer: {
                if !model.errUserkey.isEmpty {
                    let errMsg = LocalizedString(model.errUserkey)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                } else if !model.errRequestSignal.isEmpty {
                    let errMsg = LocalizedString(model.errRequestSignal)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                } else if !model.errMessage.isEmpty {
                    let errMsg = LocalizedString(model.errMessage)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                }
            }
        }.onAppear {
            UITableView.appearance().backgroundColor = .clear
        }
    }
}

I also tried using @FocusState private var focusedField: FocusedField? for every textfield with the default keyboard, but no difference. This bug doesn't appear if all the textfields are using numberPad.

I tested it using a real device running iOS 16.2 with XCode 14.2 Any ideas or suggestions?

burnsi
  • 6,194
  • 13
  • 17
  • 27
  • 1
    To make it easier to answer your question, please create a [mcve]. The code you've given doesn't compile – Ashley Mills Jan 27 '23 at 11:14
  • your code (with minor mods for my tests), works well for me on real ios 16 devices. All textfields and keyboards appear as expected. Maybe there is some other contextual code that may be responsible for your issue. Note however, I do get some warnings about satisfying constraints when I tap into another textfield. – workingdog support Ukraine Jan 28 '23 at 00:54

0 Answers0