Skip to content

[dev-v5] fix: OnSetValue in FluentAutocomplete #4747

@MarvinKlein1508

Description

@MarvinKlein1508

🐛 Bug Report

PR #4735 introduced the OnSetValue callback to the FluentAutocomplete. Initial values aren't respected by the component right now.

In addition if you use an async callback then it will be executed over and over again.

💻 Repro or Code Sample

Update the debug page to use an initialized value.

int? SelectedUserId { get; set; } = 3;

Notice that the component won't show the item on page load.

Image

To test the async code update the example to:

<FluentAutocomplete TOption="User"
                    TValue="int?"
                    Width="100%"
                    Label="@($"Bind to an Int32 (SelectedUserId: {SelectedUserId})")"
                    Multiple="false"
                    OnOptionsSearch="@(args => { args.Items = User.GetUsers().Where(u => u.Name.StartsWith(args.Text, StringComparison.OrdinalIgnoreCase)); return Task.CompletedTask; })"
                    OnSetValue="@(async (args) =>
                    {   // Put a debug point here
                        await Task.Delay(20);
                        args.Item = User.GetUsers().FirstOrDefault(u => u.Id == args.Value);
                    })"
                    OptionText="@(item => item?.Name)"
                    OptionValue="@(item => item?.Id)"
                    @bind-Value="@SelectedUserId" />

🤔 Expected Behavior

The value should be shown on page load and the async method should only run once.

😯 Current Behavior

  1. The value is only shown once you click on the component.
  2. The async method will be executed over and over again

Metadata

Metadata

Assignees

Labels

bugA bugv5For the next major version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions