Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectedValuesChanged with @bind-SelectedValues

Is it possible to do it? I'm currently trying to get a popup to show when something is selected in MudBlazor. But when i try to call the function, with the selectedvalues it never hits it.enter code here

<MudSelect T="string" MultiSelection="true" SelectAll="true" SelectAllText="Select all InputModules" HelperText="@value" @bind-Value="value" @bind-SelectedValues="SelectedInputModules" MultiSelectionTextFunc="@(new Func<List<string>, string>(GetMultiSelectionText))" Label="InputModules" AdornmentIcon="@Icons.Material.Filled.Search">
@foreach (var con in conTask.Select(x => x.InputModuleName).Distinct())
{
    <MudSelectItem T="string" Value="@con" OnClick="@(()=> ToggleInputModuleVisibility(SelectedInputModules.ToString()))">@con</MudSelectItem>
}
@code 
{    private string value { get; set; } = "Nothing selected";
private IEnumerable<string> SelectedInputModules { get; set; } = new HashSet<string>();

private string GetMultiSelectionText(List<string> selectedValues)
{
    return $"{selectedValues.Count} InputModule{(selectedValues.Count > 1 ? "s have" : " has")} been selected";
}

}

I cant quite figure out if its the logic that is off. Or if its a matter of using a different method to hit it. I tried using the "SelectedValuesChanged" but it says the parameter is already used by bind-SelectedValues

like image 530
Ramses Avatar asked Mar 27 '26 09:03

Ramses


1 Answers

Remove @bind-SelectedValues="SelectedInputModules" and use SelectedValuesChanged="OnSelectedValuesChanged":

<MudSelect T="string" MultiSelection="true" SelectAll="true" SelectAllText="Select all InputModules"
       HelperText="@value" @bind-Value="value"
       MultiSelectionTextFunc="@(new Func<List<string>, string>(GetMultiSelectionText))" Label="InputModules"
       AdornmentIcon="@Icons.Material.Filled.Search" SelectedValuesChanged="OnSelectedValuesChanged">

@foreach (var con in conTask.Select(x => x.InputModuleName).Distinct())
{
    <MudSelectItem T="string" Value="@con"> @con </MudSelectItem>
}

Then bind your SelectedInputModules manually in the OnSelectedValuesChanged method:

  private void OnSelectedValuesChanged(IEnumerable<string> values)
{
    SelectedInputModules = values;
    // Show your popup
}
like image 147
spyros__ Avatar answered Mar 29 '26 00:03

spyros__



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!