@@ -37,6 +37,9 @@ struct EditFeaturesUsingFeatureFormsView: View {
3737 /// A Boolean value indicating whether the discard edits alert is presented.
3838 @State private var isShowingDiscardEditsAlert = false
3939
40+ /// A Boolean value indicating whether any edits have been made to the feature form.
41+ @State private var hasEdits = false
42+
4043 /// A Boolean value indicating whether the feature form has any validation errors.
4144 @State private var hasValidationErrors = false
4245
@@ -69,7 +72,7 @@ struct EditFeaturesUsingFeatureFormsView: View {
6972 MapView ( map: map)
7073 . onSingleTapGesture { screenPoint, _ in
7174 if isShowingFeatureForm {
72- isShowingDiscardEditsAlert = true
75+ showDiscardEditsAlert ( )
7376 } else {
7477 tapPoint = screenPoint
7578 }
@@ -109,6 +112,15 @@ struct EditFeaturesUsingFeatureFormsView: View {
109112 FeatureFormView ( featureForm: featureForm)
110113 . padding ( . horizontal)
111114 . task {
115+ defer { hasEdits = false }
116+
117+ for await hasEdits in featureForm. $hasEdits {
118+ self . hasEdits = hasEdits
119+ }
120+ }
121+ . task {
122+ defer { hasValidationErrors = false }
123+
112124 for await validationErrors in featureForm. $validationErrors {
113125 hasValidationErrors = !validationErrors. isEmpty
114126 }
@@ -126,14 +138,15 @@ struct EditFeaturesUsingFeatureFormsView: View {
126138 Text ( " Any changes made within the form will be lost. " )
127139 }
128140 . errorAlert ( presentingError: $error)
141+ . disabled ( isApplyingEdits)
129142 }
130143 }
131144
132145 /// The toolbar for the feature form panel.
133146 private var featureFormToolbar : some View {
134147 HStack {
135148 Button ( " Discard Edits " , systemImage: " xmark.circle " , role: . destructive) {
136- isShowingDiscardEditsAlert = true
149+ showDiscardEditsAlert ( )
137150 }
138151
139152 Spacer ( )
@@ -145,7 +158,7 @@ struct EditFeaturesUsingFeatureFormsView: View {
145158 Button ( " Done " , systemImage: " checkmark " ) {
146159 isApplyingEdits = true
147160 }
148- . disabled ( hasValidationErrors)
161+ . disabled ( !hasEdits || hasValidationErrors)
149162 . task ( id: isApplyingEdits) {
150163 guard isApplyingEdits else { return }
151164 defer { isApplyingEdits = false }
@@ -169,6 +182,15 @@ struct EditFeaturesUsingFeatureFormsView: View {
169182 featureLayer. clearSelection ( )
170183 }
171184
185+ /// Shows the discard edits alert if the feature form has edits.
186+ private func showDiscardEditsAlert( ) {
187+ if hasEdits {
188+ isShowingDiscardEditsAlert = true
189+ } else {
190+ endEditing ( )
191+ }
192+ }
193+
172194 /// Applies the edits made in the feature form to the feature service.
173195 private func applyEdits( ) async throws {
174196 guard let featureForm else { return }
0 commit comments