Skip to content

Commit

Permalink
Merge pull request #86 from kishikawakatsumi/submit
Browse files Browse the repository at this point in the history
guard submit
  • Loading branch information
kishikawakatsumi authored Jul 27, 2024
2 parents b3afd68 + d9a0b67 commit b80fa0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct ConnectServerView: View {
@State private var username: String
@State private var password: String

private var canSubmit: Bool {
!server.isEmpty && !username.isEmpty && !password.isEmpty
}

@FocusState
private var focusedField: FocusedField?

Expand Down Expand Up @@ -98,7 +102,7 @@ struct ConnectServerView: View {
submit()
}
.frame(maxWidth: .infinity)
.disabled(server.isEmpty || username.isEmpty || password.isEmpty)
.disabled(!canSubmit)
}
}
.navigationTitle("Connect to Server")
Expand All @@ -113,6 +117,7 @@ struct ConnectServerView: View {
focusedField = .server
}
.onSubmit {
guard canSubmit else { return }
submit()
}
.alert(isPresented: $presentAlert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ struct ConnectServiceView: View {

@State private var username: String
@State private var password: String


private var canSubmit: Bool {
!username.isEmpty && !password.isEmpty
}

@FocusState
private var focusedField: FocusedField?

Expand Down Expand Up @@ -60,7 +64,7 @@ struct ConnectServiceView: View {
submit()
}
.frame(maxWidth: .infinity)
.disabled(username.isEmpty || password.isEmpty)
.disabled(!canSubmit)
}
}
.navigationTitle("Connect to Server")
Expand All @@ -75,6 +79,7 @@ struct ConnectServiceView: View {
focusedField = .username
}
.onSubmit {
guard canSubmit else { return }
submit()
}
.alert(isPresented: $presentAlert) {
Expand Down

0 comments on commit b80fa0e

Please sign in to comment.