From ae55a6e4e2a7f923210a33e198ca640f40a16001 Mon Sep 17 00:00:00 2001 From: dotMorten Date: Tue, 3 Sep 2024 12:33:18 -0700 Subject: [PATCH 1/4] Adds a temporary combox value when no coded value matches --- .../FeatureForm/ComboboxFormInputView.Maui.cs | 7 +++++++ .../FeatureForm/ComboboxFormInputView.Windows.cs | 7 +++++++ .../FeatureForm/ComboboxFormInputView.cs | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Maui.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Maui.cs index 628f88879..1b1eed3a5 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Maui.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Maui.cs @@ -48,6 +48,13 @@ protected override void OnApplyTemplate() private void Picker_SelectedIndexChanged(object? sender, EventArgs e) { + if(_selector?.SelectedItem is not ComboBoxPlaceHolderValue && _selector?.ItemsSource is IList list && list.LastOrDefault() is ComboBoxPlaceHolderValue) + { + // Remove placeholder if it isn't selected any longer + list.RemoveAt(list.Count - 1); + } + if (_selector?.SelectedItem is ComboBoxPlaceHolderValue) + return; var value = (_selector?.SelectedItem as CodedValue)?.Code; Element?.UpdateValue(value); } diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Windows.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Windows.cs index 10403bd7f..f6731ff93 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Windows.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.Windows.cs @@ -30,6 +30,13 @@ public override void OnApplyTemplate() private void Selector_SelectionChanged(object sender, SelectionChangedEventArgs e) { + if(_selector?.SelectedItem is not ComboBoxPlaceHolderValue && _selector?.ItemsSource is IList list && list.LastOrDefault() is ComboBoxPlaceHolderValue) + { + // Remove placeholder if it isn't selected any longer + list.RemoveAt(list.Count - 1); + } + if (_selector?.SelectedItem is ComboBoxPlaceHolderValue) + return; var value = (_selector?.SelectedItem as CodedValue)?.Code; Element?.UpdateValue(value); } diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs index d557ad0d2..e4398aced 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs @@ -85,12 +85,13 @@ private void UpdateItems() #if !MAUI _selector.DisplayMemberPath = nameof(CodedValue.Name); #endif - List items = new List(); + var items = new ObservableCollection(); if (input.NoValueOption == FormInputNoValueOption.Show) { items.Add(new ComboBoxNullValue() { Name = input.NoValueLabel }); } - items.AddRange(input.CodedValues); + foreach (var value in input.CodedValues) + items.Add(value); _selector.ItemsSource = items; UpdateSelection(); } @@ -111,6 +112,13 @@ private void UpdateSelection() var selection = input.CodedValues.Where(a => object.Equals(a.Code, Element?.Value)).FirstOrDefault(); if (selection is null && input.NoValueOption == FormInputNoValueOption.Show) _selector.SelectedIndex = 0; + else if (selection is null && Element?.Value is not null) // Attribute value not available in the domain + { + var missingValue = new ComboBoxPlaceHolderValue() { Name = Element?.Value?.ToString() }; + var items = (IList)_selector.ItemsSource; + items.Add(missingValue); + _selector.SelectedItem = missingValue; + } else _selector.SelectedItem = selection; } @@ -123,6 +131,10 @@ private class ComboBoxNullValue public string? Name { get; set; } public override string ToString() => Name!; } + + private class ComboBoxPlaceHolderValue : ComboBoxNullValue + { + } } } #endif \ No newline at end of file From 2fe71fc9fdea712cad20e527939ab70062010a14 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Tue, 3 Sep 2024 12:35:51 -0700 Subject: [PATCH 2/4] Remove unnecessary null check --- .../Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs index e4398aced..6c512ddb1 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs @@ -114,7 +114,7 @@ private void UpdateSelection() _selector.SelectedIndex = 0; else if (selection is null && Element?.Value is not null) // Attribute value not available in the domain { - var missingValue = new ComboBoxPlaceHolderValue() { Name = Element?.Value?.ToString() }; + var missingValue = new ComboBoxPlaceHolderValue() { Name = Element.Value.ToString() }; var items = (IList)_selector.ItemsSource; items.Add(missingValue); _selector.SelectedItem = missingValue; @@ -137,4 +137,4 @@ private class ComboBoxPlaceHolderValue : ComboBoxNullValue } } } -#endif \ No newline at end of file +#endif From a482f26f4dc33c07fceeb4d269533e727e186c02 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Tue, 3 Sep 2024 13:11:58 -0700 Subject: [PATCH 3/4] Add missing using --- .../Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs index 6c512ddb1..6c67b1633 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs @@ -2,6 +2,7 @@ using Esri.ArcGISRuntime.Data; using Esri.ArcGISRuntime.Mapping.FeatureForms; using Esri.ArcGISRuntime.Toolkit.Internal; +using System.Collections.ObjectModel; using System.ComponentModel; #if MAUI From 7d330e9d14ea9d8f91ab24a04c0d9738af5b1442 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Wed, 4 Sep 2024 17:20:09 -0700 Subject: [PATCH 4/4] Fix indent --- .../Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs index 6c67b1633..8b912694f 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/ComboboxFormInputView.cs @@ -135,7 +135,7 @@ private class ComboBoxNullValue private class ComboBoxPlaceHolderValue : ComboBoxNullValue { - } + } } } #endif