Blazorise icon indicating copy to clipboard operation
Blazorise copied to clipboard

Fallback to item instead of default in SelectList

Open GeertvanHorrik opened this issue 3 years ago • 3 comments

The SelectList currently enforces one to write a ValueField. Would it make sense to fallback to item instead of default?

https://github.com/Megabit/Blazorise/blob/master/Source/Extensions/Blazorise.Components/SelectList.razor#L14

Then one doesn't have to write:

<SelectList Style="width: 200px"
            TItem="MyType"
            TValue="MyType"
            Data="@MyValues"
            TextField="@((item)=>item.DisplayName)"
            ValueField="@((item)=>item)"
            @bind-SelectedValue="@SelectedValue" />

GeertvanHorrik avatar Jul 12 '22 11:07 GeertvanHorrik

Not a bad idea. @David-Moreira ?

Also, keep in mind that returning a ValueField="@((item)=>item)" has some limitations. https://blazorise.com/blog/how-to-handle-select-with-primitive-and-complex-types

stsrki avatar Jul 12 '22 11:07 stsrki

Thanks for the hint about the complex types, it was indeed the issue I was actually having. Now using a string value instead.

GeertvanHorrik avatar Jul 12 '22 12:07 GeertvanHorrik

I am not entirely sure that currently ValueField can be ommited/optional. Pretty much because the current complex types limitations. However we do plan to make that experience better in the future, and maybe then, it could be optional.

David-Moreira avatar Jul 18 '22 22:07 David-Moreira