@implements IDisposable
@page "/counter"
@using Syncfusion.Blazor.Buttons

<EditForm EditContext="@editContext">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <SfCheckBox Label="Default" @bind-Checked="starship.IsChecked" />

</EditForm>

@code {

    // https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-3.1

    public class Starship
    {
        public bool IsChecked {get; set;}
    }

    private Starship starship = new Starship();
    private bool formInvalid = true;
    private EditContext editContext;

    protected override void OnInitialized()
    {
        editContext = new EditContext(starship);
        editContext.OnFieldChanged += HandleFieldChanged;
    }

    private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
    {
        System.Console.WriteLine( "***" ); 
        formInvalid = !editContext.Validate();
        StateHasChanged();
    }

    public void Dispose()
    {
        editContext.OnFieldChanged -= HandleFieldChanged;
    }
    
}
