How can I bind to a nullable enum in FluentSelect
#3901
Unanswered
MarvinKlein1508
asked this question in
Q&A
Replies: 2 comments
-
@vnbaaij @dvoituron do you have any guidance on this? Sadly the demos don't offer any real |
Beta Was this translation helpful? Give feedback.
0 replies
-
I don't know if there's an easier way. Perhaps by creating a “Wrapper” that accepts the value However, we have greatly simplified these options in v5. https://fluentui-blazor-v5.azurewebsites.net/List/Select#optiontemplate-and-enum-values Example with null <FluentSelect Label="Colors"
Items="@GetEnumValues()"
@bind-Value="@Value">
</FluentSelect>
@code {
IEnumerable<Color?> GetEnumValues() => new Color?[] { null }.Concat(Enum.GetValues(typeof(Color)).Cast<Color?>());
Color? Value;
} Example without null <FluentSelect Label="Colors"
Items="@GetEnumValues()"
@bind-Value="@Value">
</FluentSelect>
@code {
IEnumerable<Color> GetEnumValues() => Enum.GetValues(typeof(Color)).Cast<Color>();
Color Value;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I try to figure out how I can bind to a nullable enum using the
FluentSelect
component.In my case I have a nullable enum which is part of my object. It is nullable because I don't want to provide a value for the user by default. Instead he/she should pick a value from it.
Currently I have this example code:
However now the user cannot switch back to empty state when he has selected a value before. But not all of my actions require the user to select an enum.
Is there any easy way to get it working?
Right now I'm using this work-around which isn't ideal to maintain.
Beta Was this translation helpful? Give feedback.
All reactions