@@ -420,6 +420,11 @@ private struct FilterSheetView: View {
420420 let onApply : ( ) -> Void
421421 let onClear : ( ) -> Void
422422
423+ private func bindingForFilter( _ id: UUID ) -> Binding < TableFilter > ? {
424+ guard let index = filters. firstIndex ( where: { $0. id == id } ) else { return nil }
425+ return $filters [ index]
426+ }
427+
423428 var body : some View {
424429 NavigationStack {
425430 Form {
@@ -433,30 +438,32 @@ private struct FilterSheetView: View {
433438 }
434439 }
435440
436- ForEach ( $filters) { $filter in
437- Section {
438- Picker ( " Column " , selection: $filter. columnName) {
439- ForEach ( columns, id: \. name) { col in
440- Text ( col. name) . tag ( col. name)
441+ ForEach ( filters) { filter in
442+ if let binding = bindingForFilter ( filter. id) {
443+ Section {
444+ Picker ( " Column " , selection: binding. columnName) {
445+ ForEach ( columns, id: \. name) { col in
446+ Text ( col. name) . tag ( col. name)
447+ }
441448 }
442- }
443449
444- Picker ( " Operator " , selection: $filter. filterOperator) {
445- ForEach ( FilterOperator . allCases, id: \. self) { op in
446- Text ( op. displayName) . tag ( op)
450+ Picker ( " Operator " , selection: binding. filterOperator) {
451+ ForEach ( FilterOperator . allCases, id: \. self) { op in
452+ Text ( op. displayName) . tag ( op)
453+ }
447454 }
448- }
449455
450- if filter. filterOperator. needsValue {
451- TextField ( " Value " , text: $filter . value)
452- . textInputAutocapitalization ( . never)
453- . autocorrectionDisabled ( )
454- }
456+ if filter. filterOperator. needsValue {
457+ TextField ( " Value " , text: binding . value)
458+ . textInputAutocapitalization ( . never)
459+ . autocorrectionDisabled ( )
460+ }
455461
456- if filter. filterOperator == . between {
457- TextField ( " Second value " , text: $filter. secondValue)
458- . textInputAutocapitalization ( . never)
459- . autocorrectionDisabled ( )
462+ if filter. filterOperator == . between {
463+ TextField ( " Second value " , text: binding. secondValue)
464+ . textInputAutocapitalization ( . never)
465+ . autocorrectionDisabled ( )
466+ }
460467 }
461468 }
462469 }
0 commit comments