CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.
https://mudextensions.codebeam.org/
MIT License
367 stars 62 forks source link

MudComboBox Search Selection Conversion Type Error #256

Open PlayerModu opened 11 months ago

PlayerModu commented 11 months ago

When using the MudComboBox with T of an object type, and using the default search box, I am seeing a type conversion error underneath the component when I select one or more of the options in the list. However I do not see this type conversion error if I scroll through and select the same objects from the list manually.

Error: "Conversion to type PersonDto not implemented"

I've tried to include the relevant code below:

 private IEnumerable<PersonDto> _peopleToOverwrite;
 private List<PersonDto> _PeopleList;
..
<MudComboBox T="PersonDto"
    @bind-SelectedValues="_peopleToOverwrite"
    Label="People"
    Clearable="true"
    ShowCheckbox="true"
    Editable="true"
    MultiSelection="true"
    Margin="Margin.Dense">
    @foreach (var item in _PeopleList)
    {
        <MudComboBoxItem Value="@item"
            Text="@("P0" + @item.Name+ " - " + @item.City)">
            @item
        </MudComboBoxItem>
    }
</MudComboBox>

Please can you advise? This is a hard-blocker to me using this component. Given the docs only show an example of a simple string type, I can't see if it's a me issue or a component issue.

Notes - I'm using the latest version of this library and MudBlazor

PlayerModu commented 10 months ago

Working try.* snippet which shows the issue. Posting on here for exposure incase anyone else has this issue and isn't on the Discord ☺️

<MudComboBox T="PracticeInformationDto"  @bind-SelectedValues="_practicesToOverwrite"
    Label="Practice"
    Clearable="true"
    ShowCheckbox="true"
    Editable="true"
    MultiSelection="true"
    Margin="Margin.Dense">
    @foreach (var item in _filteredPracticesToOverwrite)
    {
        <MudComboBoxItem Value="@item"
            Text="@("P0" + @item.PracticeCode + " - " + @item.PracticeName)">
            @item
        </MudComboBoxItem>
    }
</MudComboBox>

@code {
    public class PracticeInformationDto
    {
        public string PracticeCode { get; set; }
        public string PracticeName { get; set; }
    }

    private List<PracticeInformationDto> _filteredPracticesToOverwrite = new()
        {
            new PracticeInformationDto()
            {
                PracticeCode = "1234",
                PracticeName = "ABC"
            },
            new PracticeInformationDto()
            {
                PracticeCode = "4321",
                PracticeName = "CBA"
            },
        };

    private IEnumerable<PracticeInformationDto> _practicesToOverwrite;
}
PlayerModu commented 10 months ago

Updating:

Until this can be done automatically, this error can be resolved by passing a custom converter to the Converter property on the MudComboxBox

    Converter<PracticeInformationDto> _converter = new Converter<PracticeInformationDto>
    {
        SetFunc = value => value.PracticeName
    };