CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.

Home Page:https://mudextensions.codebeam.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MudSelect Chips Render

softbunnyware opened this issue · comments

``Hello!

I have one problem and I realy don't know how to solve it. When I select the data in the select box the chips does show, but as soon as I close the drawer the chips dissaper.
If I use the select as normal I do get get the strings.

@typeparam TEntity where TEntity : IBunnyClientResponseExtensions
@typeparam TId
@inject IBunnyClient Client

@using System.Linq.Expressions;

<MudSelectExtended T="TId" MultiSelection="true" SelectedValues="@SelectedValues" SelectedValuesChanged="@SelectedValuesChanged" 
                   Label="@Label" Dense="true" Style="margin:5px;" For="@For" ValuePresenter="MudExtensions.Enums.ValuePresenter.Chip"
                   ChipCloseable="true" ChipVariant="MudBlazor.Variant.Filled" ChipSize="MudBlazor.Size.Small"
                   Variant="Variant.Outlined" Margin="Margin.Dense" >
    @if (List != null)
    {
        @foreach (var item in List)
        {
            <MudSelectItemExtended T="int" Value="@item.Id" Text="@item.Name" />
        }
    }
</MudSelectExtended>

@code {
    [Parameter] public IEnumerable<TId> SelectedValues { get; set; } = default!;
    [Parameter] public EventCallback<IEnumerable<TId>> SelectedValuesChanged { get; set; }
    [Parameter] public Expression<Func<TId>> For { get; set; }
    [Parameter] public string Label { get; set; }
    [Parameter] public SelectFieldContext<TEntity> Context { get; set; } = default!;

    List<TEntity>? List { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        if (await APIWrapper.ExecuteCallGuardedAsync(
                () => Context.LoadAllFunc(), Snackbar)
            is { } result)
        {
            List = result.Adapt<List<TEntity>>();
        }
    }
}

This is my select components

<SelectFieldMulti @bind-SelectedValues="Request.Sectors" For="(() => Request.ContractorId)" Context="SectorSelectContext" Label="@L["Sectors"]" />

This is how I use component

The Request.Sectors is a List

If i remove this part of code I do get selected sectors seperated by comma

ValuePresenter="MudExtensions.Enums.ValuePresenter.Chip"
ChipCloseable="true" ChipVariant="MudBlazor.Variant.Filled" ChipSize="MudBlazor.Size.Small"

Can you please help me where is the problem.

I am using 6.6.3

Okei I have tried with the Combobox and did it a bit differently but it doesnt work :(
When I try to edit the Request I get the black Combobox, it works fine if I am on Create form.

<ComboField T="SectorResponse" @bind-Value="Request.Sector" 
For="(() => Request.Sector)" MultiSelection="false" Label="@L["Label"]">
    <ComboFields Context="SectorSelectContext" T="SectorResponse"/>
</ComboField>

This is the Edit form

public class ComboField<T> : MudComboBox<T>
        where T : IBunnyClientResponseExtensions
    {
        [Parameter] public bool IsMultiSelect { get; set; } = true;

        public override Task SetParametersAsync(ParameterView parameters)
        {
            Variant = Variant.Text;
            Margin = Margin.Dense;
            ItemPresenter = ValuePresenter.Chip;
            InputPresenter = ValuePresenter.Chip;
            ChipCloseable = true;
            Editable = true;
            Color = Color.Primary;
            ChipVariant = Variant.Text;
            ChipSize = Size.Small;
            MultiSelection = IsMultiSelect;
            ToStringFunc = x => GetString(x);
            return base.SetParametersAsync(parameters);
        }

        private string GetString(T entity)
        {
            return entity.DisplayName ?? default!;
        }
    }

This is the ComboFields

@typeparam T where T : IBunnyClientResponseExtensions

@foreach (var item in List)
{
    <MudComboBoxItem Text="@item.DisplayName" Value="@item"></MudComboBoxItem>
}
@code {
    private List<T> List { get; set; } = new List<T>();
    [Parameter] public ComboFieldContext<T> Context { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        if (await APIWrapper.ExecuteCallGuardedAsync(
        () => Context.LoadAllFunc(), null)
            is { } result)
        {
            List = result.Adapt<List<T>>();
        }
    }
}

Am I Stupid or where is the problem that the initial value is Null when I use this field on EditForm