-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Razor Components] Check-boxes behaving strangely in lists. #8202
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
Comments
Was searching for a solution to a problem exactly like what you describe and found your very new ticket. |
Thanks for contacting us, @davidbmasterson. |
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project that illustrates the problem. |
@javiercn, could you please investigate this, when we'll get a repro? Thanks! |
here is the repro https://github.com/davidbmasterson/exampleproject_checkboxes have fun |
I repro this with our latest bits. Looking into it. |
The issue here is that the act of clicking the checkbox modifies the state of the component. Our diffing algorithms produces a set of instructions that tell the browser to do the following (roughly)
The problem is that in this case checking the first checkbox in the second list marks the checkbox as checked, which the server model does not have any idea about. There are several ways we can avoid this.
In any case, this can't be a small fix but something with a bigger scope. |
Closing as the recommended action in this situation is to use |
With 2 for loops one for checked items and one for unchecked items.
When you check the first item on the unchecked list, the first item moves to the checked list and disappears from the unchecked list as you would expect.
However what was the second item in the unchecked list is now showing as checked in the page and false in the underlying List this continues to happen if you check other items
it works as expected if you start from the bottom of the list
Using
Using Visual studio 2019 version 16.0.0 Preview 4
Dot Net Core 3.0 preview 2
Create a razor components site
Replace the code in index.cshtml with
`@page "/"
checked items
@foreach (var story in Stories.Where(c => c.Checked == true).ToArray()) {- @story.Description
}
unchecked items
@foreach (var story in Stories.Where(c => c.Checked == false).ToArray()) {- @story.Description
}
state of values in list
@foreach (var story in Stories) { }@functions {
}`
State after clicking first item on unchecked list only

I would expect items checked or unchecked in either list to move from one list to the other and for this to have no effect on the other check-boxes
The text was updated successfully, but these errors were encountered: