Last active
February 14, 2026 20:08
-
-
Save StewartLynch/e0728488737d0ea3a29b63711d361343 to your computer and use it in GitHub Desktop.
Gift Form View for Gift Registry SQLiteData series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct GiftForm: View { | |
| @State private var name = "" | |
| @State private var price: Double? | |
| @State private var isPurchased = false | |
| @Environment(\.dismiss) var dismiss | |
| var body: some View { | |
| NavigationStack { | |
| Form { | |
| Section("Gift Details") { | |
| TextField("Gift Name", text: $name) | |
| LabeledContent("Price") { | |
| TextField("Price", value: $price, | |
| format: .currency( | |
| code: Locale.current.currency?.identifier ?? "USD" | |
| ) | |
| ) | |
| .keyboardType(.decimalPad) | |
| .multilineTextAlignment(.trailing) | |
| } | |
| Toggle("Purchased", isOn: $isPurchased) | |
| } | |
| } | |
| .navigationTitle("Gift") | |
| .navigationBarTitleDisplayMode(.inline) | |
| .toolbar { | |
| ToolbarItem(placement: .cancellationAction) { | |
| Button("Cancel") { | |
| dismiss() | |
| } | |
| } | |
| ToolbarItem(placement: .confirmationAction) { | |
| Button("Save") { | |
| dismiss() | |
| } | |
| .disabled(name.trimmingCharacters(in: .whitespaces).isEmpty) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| #Preview { | |
| GiftForm() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment