Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeatureForms: Adds a temporary combox value when no coded value matches #601

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading