Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Why are the checkboxes still checkable?

$
0
0

Why are the checkboxes still checkable?

@if (@GearTypeView.PickN > 1){    @foreach (GearView gearView in GearTypeView.GearViews)    {<div class="row"><div class="col m-1"><input type="checkbox"                       checked="@IsChecked(gearView.GearId)"                       @onchange="(ChangeEventArgs args) => { OnGearChanged(args, gearView.GearId); }" />&nbsp;                @gearView.GearDescription</div></div>    }}@code {    [Parameter]    public GearTypeView GearTypeView { get; set; } = new();    private List<int> selectedGearIds = new();    private void OnGearChanged(ChangeEventArgs args, int gearId)    {        bool isChecked = (Boolean)args.Value;        if (isChecked &&            !selectedGearIds.Contains(gearId) &&            selectedGearIds.Count < GearTypeView.PickN)        {            selectedGearIds.Add(gearId);        }        else if (!isChecked && selectedGearIds.Contains(gearId))        {            selectedGearIds.Remove(gearId);        }    }    private bool IsChecked(int gearId)    {        bool isChecked = selectedGearIds.Contains(gearId);        return isChecked;    }}

When I put a breakpoint at the end of OnGearChanged(), the list of checked checkboxes is being updated appropriately, including not allowing more than the max (called PickN). When I put a breakpoint at the end of IsChecked(), the evaluation returns the expected true/false. & every time a checkbox is clicked, IsChecked() is being called. I tried adding StateHasChanged() to the end of OnGearChanged(), but the same unexpected behavior is exhibited.

Thanks in advance!


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>