-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Fix InputSelect not handling null for nullable bool #65222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@dotnet-policy-service agree |
|
|
||
| // See: https://github.com/dotnet/aspnetcore/pull/54565 | ||
| [Fact] | ||
| public async Task ParsesNullWhenUsingNullableBool() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add symmetric test to int/guid coverage:
ParsesCurrentValueWhenUsingNullableBoolParsesCurrentValueWhenUsingNotNullableBool
|
This change should be done as a part of more complex fix that contains also improving #41222. |
Potentially although it would depend on the approach taken to fix that issue. If the fix were to try and mirror the state of the HTML (i.e. when the select element automatically is displaying the first option, update the bound value to reflect the first option) then these two cases would be unlikely to intersect. I personally think this is probably a good approach as it is more reflective of the actual behaviour of a select element and so more intuitive for someone with little or no blazor experience. It is also possible other approaches don't intersect with this particular issue, and from the discussion it doesn't seem there is an agreed upon way to approach this yet. |
I've had more of a look at this today. To do what I thought would be a good idea, seems like it would probably involve JS interop and so may not be a great candidate. Alternatively, a solution could involve inspecting the Apologies for going off topic on this a little bit, this is just something that pops up more in my own projects. |
|
@m-e-lloyd thanks for the additional details. Mostly we want to avoid doing a set of "local" fixes (that might conflict with each other) and take a more complete look to better define how everything should work. There are several issues that came up with I think we are going to hold off on the current change until we get some cycles to figure that out. |
|
As this has been broken since .NET 8 would it not be better to fix this specific issue with |
Fix nullable bool parsing on InputSelect component
Summary
This PR fixes an issue in
InputSelectwhere setting the value tonullfor a nullable boolean (bool?) would fail to correctly parse a null value.The root cause was that
InputSelectdid not handlenullvalues correctly. This fix adds a null check inInputSelectto allowCurrentValueto be set tonull.Description
When binding a
bool?to a InputSelect compoenent, the current implementation ofFormatValueAsString(TValue value)does not handle null values and always returnstrueorfalse.Changes:
InputSelectforbool?.ParsesNullWhenUsingNullableBooltest to confirmnullis correctly handled.NullableBool)Fixes #54565