I am trying to create a simple lunch scheme webapp, where you can sign up for any business day of the week. I want the user to be able to select each day individually or select a whole week.
What I thought would be a simple method call/check is proving to be seemingly impossible in a Blazor razorpage. I want a checkbox for the whole week, which checks or unchecks all the checkboxes for each individual day. This is pretty straightforward and works as expected. But if I uncheck any of the days, I want the week checkbox to get unchecked as well.
This is what the relevant part of my page looks like:
@foreach (var item in weeks)
{
<tr>
<td><input type="checkbox" @onchange="eventArgs => SetAllWeekDays(item.Key, eventArgs.Value)" /> @item.Value.WeekNumber</td>
<td>
<input type="checkbox" @bind="item.Value.WeekDays[0].IsSignedUp" />
</td>
<td>
<input type="checkbox" @bind="item.Value.WeekDays[1].IsSignedUp" />
</td>
<td>
<input type="checkbox" @bind="item.Value.WeekDays[2].IsSignedUp" />
</td>
<td>
<input type="checkbox" @bind="item.Value.WeekDays[3].IsSignedUp" />
</td>
<td>
<input type="checkbox" @bind="item.Value.WeekDays[4].IsSignedUp" />
</td>
</tr>
}
And this is the SetAllWeekDays method:
private void SetAllWeekDays(int weekNumber, object checkedValue)
{
if ((bool)checkedValue)
{
for (int i = 0; i < weeks[weekNumber].WeekDays.Count; i++)
{
weeks[weekNumber].WeekDays[i].IsSignedUp = true;
}
}
else
{
for (int i = 0; i < weeks[weekNumber].WeekDays.Count; i++)
{
weeks[weekNumber].WeekDays[i].IsSignedUp = false;
}
}
}
When I check or uncheck the week, it checks or unchecks all the days, but if I check or uncheck any of the days individually, the checkbox for the week stays unchanged
I feel like I'm missing some obvious way of databinding a method call to the value of the whole week, as you can't both bind a value and set an @onchange event.

