Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -6209,6 +6209,12 @@
⚠️ Only available when Multiple = false.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.SelectedOptionExpression">
<summary>
Gets or sets an expression that identifies the bound selected options.
⚠️ Only available when Multiple = false.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.Multiple">
<summary>
If true, the user can select multiple elements.
Expand Down Expand Up @@ -6238,6 +6244,12 @@
⚠️ Only available when Multiple = true.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.SelectedOptionsExpression">
<summary>
Gets or sets an expression that identifies the bound selected options.
⚠️ Only available when Multiple = true.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.#ctor">
<summary />
</member>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

<h1>Autocomplete</h1>

<blockquote>
@(new MarkupString(DemoNavProvider.EditFormOffIcon))
The <b>FluentAutocomplete</b> component is not yet fully compatible with the <code>EditForm</code> and <code>FluentEditForm</code> elements.
Some functionalities, such as error messages, the requirement message or the validation messages are missing.
</blockquote>

<h2 id="example">Examples</h2>

<DemoSection Title="Default" Component="@typeof(AutocompleteDefault)" />
Expand Down
1 change: 1 addition & 0 deletions examples/Demo/Shared/SampleData/Starship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Country>? Countries { get; set; }

[Required(ErrorMessage = "A classification is required")]
Expand Down
44 changes: 29 additions & 15 deletions src/Core/Components/List/ListComponentBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public abstract partial class ListComponentBase<TOption> : FluentInputBase<strin

// We cascade the _internalListContext to descendants, which in turn call it to add themselves to the options list
internal InternalListContext<TOption> _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)
{
Expand Down Expand Up @@ -147,6 +148,13 @@ protected string? InternalValue
[Parameter]
public virtual EventCallback<TOption?> SelectedOptionChanged { get; set; }

/// <summary>
/// Gets or sets an expression that identifies the bound selected options.
/// ⚠️ Only available when Multiple = false.
/// </summary>
[Parameter]
public Expression<Func<TOption>>? SelectedOptionExpression { get; set; }

/// <summary>
/// If true, the user can select multiple elements.
/// ⚠️ Only available for the FluentSelect and FluentListbox components.
Expand Down Expand Up @@ -181,6 +189,13 @@ protected string? InternalValue
[Parameter]
public virtual EventCallback<IEnumerable<TOption>?> SelectedOptionsChanged { get; set; }

/// <summary>
/// Gets or sets an expression that identifies the bound selected options.
/// ⚠️ Only available when Multiple = true.
/// </summary>
[Parameter]
public Expression<Func<IEnumerable<TOption>>>? SelectedOptionsExpression { get; set; }

/// <summary />
public ListComponentBase()
{
Expand Down Expand Up @@ -293,11 +308,19 @@ public override async Task SetParametersAsync(ParameterView parameters)

if (!_hasInitializedParameters)
{
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);
}
Expand Down Expand Up @@ -527,19 +550,8 @@ protected virtual async Task OnSelectedItemChangedHandlerAsync(TOption? item)
{
if (!Equals(item, SelectedOption))
{
var value = GetOptionValue(item);

if (this is FluentListbox<TOption> ||
this is FluentCombobox<TOption> ||
(this is FluentSelect<TOption> && Value is null))
{
await base.ChangeHandlerAsync(new ChangeEventArgs() { Value = value });
}

SelectedOption = item;

//InternalValue = Value = value;
InternalValue = value;
InternalValue = GetOptionValue(item);
await RaiseChangedEventsAsync();
}
}
Expand All @@ -562,6 +574,8 @@ protected virtual async Task RaiseChangedEventsAsync()
await SelectedOptionChanged.InvokeAsync(SelectedOption);
}
}

await base.ChangeHandlerAsync(new ChangeEventArgs() { Value = InternalValue });
}

protected virtual async Task OnKeydownHandlerAsync(KeyboardEventArgs e)
Expand Down
Loading