Add next for text fields

multistore
Laurent 1 year ago
parent 7a1c854e67
commit a1267fbacf
  1. 36
      PadelClub/Views/User/UserCreationView.swift

@ -10,17 +10,26 @@ import LeStorage
struct UserCreationFormView: View { struct UserCreationFormView: View {
@FocusState private var focusedField: Field?
fileprivate enum Field: Int, Hashable {
case username
case password1
case password2
case email
case firstName
case lastName
case phone
}
@EnvironmentObject var networkMonitor: NetworkMonitor @EnvironmentObject var networkMonitor: NetworkMonitor
@Binding var isPresented: Bool @Binding var isPresented: Bool
@Binding var showEmailValidationMessage: Bool @Binding var showEmailValidationMessage: Bool
// @Binding var showLoginScreen: Bool
@State var username: String = "" @State var username: String = ""
@State var email: String = ""
@State var password1: String = "" @State var password1: String = ""
@State var password2: String = "" @State var password2: String = ""
@State var email: String = ""
@State var firstName: String = "" @State var firstName: String = ""
@State var lastName: String = "" @State var lastName: String = ""
@ -51,23 +60,44 @@ struct UserCreationFormView: View {
TextField("Nom d'utilisateur", text: self.$username) TextField("Nom d'utilisateur", text: self.$username)
.autocorrectionDisabled() .autocorrectionDisabled()
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
.submitLabel(.next)
.focused($focusedField, equals: Field.username)
.onSubmit { self.focusedField = Field.email }
TextField("Email", text: self.$email) TextField("Email", text: self.$email)
.keyboardType(.emailAddress) .keyboardType(.emailAddress)
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
.submitLabel(.next)
.focused($focusedField, equals: Field.email)
.onSubmit { self.focusedField = Field.password1 }
} }
Section { Section {
SecureField("Mot de passe", text: self.$password1) SecureField("Mot de passe", text: self.$password1)
.submitLabel(.next)
.focused($focusedField, equals: Field.password1)
.onSubmit { self.focusedField = Field.password2 }
SecureField("Confirmez le mot de passe", text: self.$password2) SecureField("Confirmez le mot de passe", text: self.$password2)
.submitLabel(.next)
.focused($focusedField, equals: Field.password2)
.onSubmit { self.focusedField = Field.firstName }
} }
Section { Section {
TextField("Prénom", text: self.$firstName) TextField("Prénom", text: self.$firstName)
.submitLabel(.next)
.autocorrectionDisabled() .autocorrectionDisabled()
.focused($focusedField, equals: Field.firstName)
.onSubmit { self.focusedField = Field.lastName }
TextField("Nom", text: self.$lastName) TextField("Nom", text: self.$lastName)
.submitLabel(.next)
.autocorrectionDisabled() .autocorrectionDisabled()
.focused($focusedField, equals: Field.lastName)
.onSubmit { self.focusedField = Field.phone }
TextField("Téléphone", text: self.$phone) TextField("Téléphone", text: self.$phone)
.submitLabel(.next)
.autocorrectionDisabled() .autocorrectionDisabled()
.focused($focusedField, equals: Field.phone)
// .onSubmit { self.focusNextField($focusedField) }
LabeledContent { LabeledContent {
Picker(selection: $selectedCountryIndex) { Picker(selection: $selectedCountryIndex) {

Loading…
Cancel
Save