Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created November 17, 2022 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizard1066/b526f7e40e711170d5b43837fd087f6c to your computer and use it in GitHub Desktop.
Save wizard1066/b526f7e40e711170d5b43837fd087f6c to your computer and use it in GitHub Desktop.
struct PassForm: View {
@ObservedObject var model: PassModel
@State private var buttonIsDisabled = true
var body: some View {
VStack {
Text("Password Form")
.font(.headline)
Form {
TextField("field I ", text: $model.firstEntry)
.textFieldStyle(RoundedBorderTextFieldStyle())
.lineLimit(1)
.multilineTextAlignment(.center)
.padding()
TextField("field II ", text: $model.secondEntry)
.textFieldStyle(RoundedBorderTextFieldStyle())
.multilineTextAlignment(.center)
.padding()
VStack {
ForEach(model.validationMessages, id: \.self) { msg in
HStack {
Spacer()
Text(msg)
.foregroundColor(.red)
Spacer()
}
}
}
}
Button(action: {}) {
Text("Submit")
}.disabled(buttonIsDisabled)
.onReceive(model.submitAllowed) { submitAllowed in
self.buttonIsDisabled = !submitAllowed
}
.padding()
.background(RoundedRectangle(cornerRadius: 10)
.stroke(Color.blue, lineWidth: 1)
)
Spacer()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment