Blazorise
Blazorise copied to clipboard
Fallback to item instead of default in SelectList
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" />
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
Thanks for the hint about the complex types, it was indeed the issue I was actually having. Now using a string value instead.
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.