Skip to content

Commit

Permalink
disable input if title is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rex committed Oct 24, 2024
1 parent 1204cd7 commit 4e64e6b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mobile-client/ToDoList/View/AddToDoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ struct ToDoTitleField: View {
@Binding var title: String

var body: some View {
TextField("Enter To-Do Title", text: $title)
TextField("To-Do Title (Required, max 32 characters)", text: $title)
.frame(maxWidth: .infinity)
.frame(height: 42)
.padding(.horizontal)
.background(Color(.systemGray5))
.cornerRadius(5)
.foregroundColor(title.isEmpty ? .gray : .black)
}
}

Expand Down Expand Up @@ -316,20 +317,26 @@ struct TagItem: View {
struct ActionButtons: View {
@Bindable var store: StoreOf<AddToDoReducer>

private var isTitleValid: Bool {
let title = store.todo.title
return !title.isEmpty && title.count <= 32
}

var body: some View {
VStack(spacing: 12) {
Button(action: {
if !store.isSaving {
if isTitleValid, !store.isSaving {
store.send(.saveButtonTapped)
}
}) {
Text("Add")
.frame(maxWidth: .infinity)
.frame(height: 42)
.background(Color.blue)
.background(isTitleValid ? Color.blue : Color.gray)
.foregroundColor(.white)
.cornerRadius(5)
}
.disabled(!isTitleValid)

Button(action: {
if !store.isSaving {
Expand Down

0 comments on commit 4e64e6b

Please sign in to comment.