diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
index a62b243597..c161ee7262 100644
--- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
+++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
@@ -6209,6 +6209,12 @@
⚠️ Only available when Multiple = false.
+
+
+ Gets or sets an expression that identifies the bound selected options.
+ ⚠️ Only available when Multiple = false.
+
+
If true, the user can select multiple elements.
@@ -6238,6 +6244,12 @@
⚠️ Only available when Multiple = true.
+
+
+ Gets or sets an expression that identifies the bound selected options.
+ ⚠️ Only available when Multiple = true.
+
+
diff --git a/examples/Demo/Shared/Pages/List/Autocomplete/AutocompletePage.razor b/examples/Demo/Shared/Pages/List/Autocomplete/AutocompletePage.razor
index edb614c842..30e7ab4c84 100644
--- a/examples/Demo/Shared/Pages/List/Autocomplete/AutocompletePage.razor
+++ b/examples/Demo/Shared/Pages/List/Autocomplete/AutocompletePage.razor
@@ -6,12 +6,6 @@
Autocomplete
-
- @(new MarkupString(DemoNavProvider.EditFormOffIcon))
- The FluentAutocomplete component is not yet fully compatible with the EditForm and FluentEditForm elements.
- Some functionalities, such as error messages, the requirement message or the validation messages are missing.
-
-
Examples
diff --git a/examples/Demo/Shared/SampleData/Starship.cs b/examples/Demo/Shared/SampleData/Starship.cs
index d633d51ffe..0275855318 100644
--- a/examples/Demo/Shared/SampleData/Starship.cs
+++ b/examples/Demo/Shared/SampleData/Starship.cs
@@ -20,6 +20,7 @@ public class Starship
public string? Description { get; set; }
[Required(ErrorMessage = "Countries are required")]
+ [MinLength(1, ErrorMessage = "Countries are required")]
public IEnumerable? Countries { get; set; }
[Required(ErrorMessage = "A classification is required")]
diff --git a/src/Core/Components/List/ListComponentBase.razor.cs b/src/Core/Components/List/ListComponentBase.razor.cs
index 6d76da0df5..d80fbd14c0 100644
--- a/src/Core/Components/List/ListComponentBase.razor.cs
+++ b/src/Core/Components/List/ListComponentBase.razor.cs
@@ -3,6 +3,7 @@
// ------------------------------------------------------------------------
using System.Diagnostics.CodeAnalysis;
+using System.Linq.Expressions;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
@@ -37,7 +38,7 @@ public abstract partial class ListComponentBase : FluentInputBase _internalListContext;
- internal override bool FieldBound => Field is not null || ValueExpression is not null || ValueChanged.HasDelegate || SelectedOptionChanged.HasDelegate || SelectedOptionsChanged.HasDelegate;
+ internal override bool FieldBound => Field is not null || ValueExpression is not null || ValueChanged.HasDelegate || SelectedOptionChanged.HasDelegate || SelectedOptionExpression is not null || SelectedOptionsChanged.HasDelegate || SelectedOptionsExpression is not null;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
@@ -149,6 +150,13 @@ protected string? InternalValue
[Parameter]
public virtual EventCallback SelectedOptionChanged { get; set; }
+ ///
+ /// Gets or sets an expression that identifies the bound selected options.
+ /// ⚠️ Only available when Multiple = false.
+ ///
+ [Parameter]
+ public Expression>? SelectedOptionExpression { get; set; }
+
///
/// If true, the user can select multiple elements.
/// ⚠️ Only available for the FluentSelect and FluentListbox components.
@@ -183,6 +191,13 @@ protected string? InternalValue
[Parameter]
public virtual EventCallback?> SelectedOptionsChanged { get; set; }
+ ///
+ /// Gets or sets an expression that identifies the bound selected options.
+ /// ⚠️ Only available when Multiple = true.
+ ///
+ [Parameter]
+ public Expression>>? SelectedOptionsExpression { get; set; }
+
///
public ListComponentBase()
{
@@ -295,11 +310,20 @@ public override async Task SetParametersAsync(ParameterView parameters)
}
}
- if (SelectedOptionChanged.HasDelegate)
+
+ if (SelectedOptionExpression is not null)
+ {
+ FieldIdentifier = FieldIdentifier.Create(SelectedOptionExpression);
+ }
+ else if (SelectedOptionChanged.HasDelegate)
{
FieldIdentifier = FieldIdentifier.Create(() => SelectedOption);
}
- if (SelectedOptionsChanged.HasDelegate)
+ else if (SelectedOptionsExpression is not null)
+ {
+ FieldIdentifier = FieldIdentifier.Create(SelectedOptionsExpression);
+ }
+ else if (SelectedOptionsChanged.HasDelegate)
{
FieldIdentifier = FieldIdentifier.Create(() => SelectedOptions);
}
@@ -529,19 +553,8 @@ protected virtual async Task OnSelectedItemChangedHandlerAsync(TOption? item)
{
if (!Equals(item, SelectedOption))
{
- var value = GetOptionValue(item);
-
- if (this is FluentListbox ||
- this is FluentCombobox ||
- (this is FluentSelect && Value is null))
- {
- await base.ChangeHandlerAsync(new ChangeEventArgs() { Value = value });
- }
-
SelectedOption = item;
-
- //InternalValue = Value = value;
- InternalValue = value;
+ InternalValue = GetOptionValue(item);
await RaiseChangedEventsAsync();
}
}
@@ -564,6 +577,8 @@ protected virtual async Task RaiseChangedEventsAsync()
await SelectedOptionChanged.InvokeAsync(SelectedOption);
}
}
+
+ await base.ChangeHandlerAsync(new ChangeEventArgs() { Value = InternalValue });
}
protected virtual async Task OnKeydownHandlerAsync(KeyboardEventArgs e)