Post

Replies

Boosts

Views

Activity

Reply to Problem with TextFields and decimals iOS17
I should actually clarify - this is not working when textField is in .sheet on .fullScreenCover. The code looks like so: Main View import SwiftUI struct TestFloatView: View { @ObservedObject var testFloatVM: TestFloatViewModel @State private var showAddLoad = false var body: some View { VStack { HStack { Button { showAddLoad = true } label: { Text("Text") } } } .fullScreenCover(isPresented: $showAddLoad, content: { NavigationView { EnterFloatView(testFloatVM: testFloatVM) .navigationBarItems( leading: Button(action: { showAddLoad = false }, label: { Text("Cancel") .foregroundColor(Color("AccentRed")) }), trailing: Button(action: { showAddLoad = false }, label: { Text("Save") .fontWeight(.bold) }) ) .navigationBarTitleDisplayMode(.inline) } }) } } Sheet View import SwiftUI struct EnterFloatView: View { @ObservedObject var testFloatVM: TestFloatViewModel let formatter: NumberFormatter = { let formatter = NumberFormatter() formatter.numberStyle = .decimal return formatter }() var body: some View { VStack { HStack { Text("Enter Float Number") Spacer() } Spacer() .frame(height: 2.0) HStack { TextField("Enter Float Number", value: $testFloatVM.testFloat.testFloatNumber, formatter: formatter) .keyboardType(.decimalPad) .textFieldStyle(.roundedBorder) } } } } If text field is placed in main view like in my original post, then it works OK.
Oct ’23