Skip to content

Commit

Permalink
FeatureForms: Adds a temporary combox value when no coded value match…
Browse files Browse the repository at this point in the history
…es (#601)

* Adds a temporary combox value when no coded value matches
  • Loading branch information
dotMorten authored Sep 5, 2024
1 parent cf26290 commit d06f4e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,12 +86,13 @@ private void UpdateItems()
#if !MAUI
_selector.DisplayMemberPath = nameof(CodedValue.Name);
#endif
List<object> items = new List<object>();
var items = new ObservableCollection<object>();
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();
}
Expand All @@ -111,6 +113,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<object>)_selector.ItemsSource;
items.Add(missingValue);
_selector.SelectedItem = missingValue;
}
else
_selector.SelectedItem = selection;
}
Expand All @@ -123,6 +132,10 @@ private class ComboBoxNullValue
public string? Name { get; set; }
public override string ToString() => Name!;
}

private class ComboBoxPlaceHolderValue : ComboBoxNullValue
{
}
}
}
#endif
#endif

0 comments on commit d06f4e1

Please sign in to comment.