-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewItemView.swift
42 lines (39 loc) · 1.29 KB
/
NewItemView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import SwiftUI
struct NewItemView: View {
@StateObject var viewModel = NewItemViewViewModel()
@Binding var newItemPresented: Bool
var body: some View {
VStack {
Text("New Item")
.font(.system(size: 32))
.bold()
.padding(.top, 100)
Form {
Text("Title", text: $viewModel.title)
.textFieldStyle(DefaultTextFieldStyle())
Datepicker("Due Date", selection: $viewModel.dueDate)
.datePickerStyle(GraphicalDatePickerStyle())
TLButton(title: "Save", background: .pink) {
if viewModel.canSave {
viewModel.save()
newItempresented = false
} else {
viewModel.showAlert = true
}
}
.padding()
}
.alert(isPresented: $viewModel.showAlert) {
Alert(title: Text("Error"), message: Text("Please fill in all required fields"))
}
}
}
}
struct NewItemView_Previews: PreviewProvider {
static var previews: some View {
NewItemView(newItemPresented: Binding(get: {
return true
}, set: { _ in
}))
}
}