CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.
https://mudextensions.codebeam.org/
MIT License
348 stars 60 forks source link

MudLoadingButton does not submit a form #343

Open danielgreen opened 4 months ago

danielgreen commented 4 months ago

Paste the following into the playground

Clicking the MudLoadingButton does not trigger the Submit method to increment the counter, but clicking the MudButton does increment the counter.

As both buttons have ButtonType="ButtonType.Submit" I expected they would behave in the same way.

<MudText Typo="Typo.h6">Counter is @Counter</MudText>

<EditForm Enhance FormName="Form1" Model="fooModel" OnSubmit="Submit">
    <MudTextField Label="Text" @bind-Value="fooModel.Text" For="@(() => fooModel.Text)" />

    <MudLoadingButton ButtonType="ButtonType.Submit" @bind-Loading="saving" Size="Size.Small" Variant="Variant.Filled" LoadingAdornment="Adornment.Start" Color="Color.Primary" Class="mt-1">
        <LoadingContent>
            Saving
        </LoadingContent>
        <ChildContent>
            Save
        </ChildContent>
    </MudLoadingButton>

    <MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">@ButtonText</MudButton>

</EditForm>

@code {
    public int Counter;
    public bool saving;

    public class Foo
    {
        public string Text { get; set; } = "????";
    }

    public Foo fooModel = new Foo();

    public string ButtonText { get; set; } = "Click Me";

    protected override void OnInitialized()
    {
        Counter = 0;
    }

    async Task Submit()
    {
        saving = true;
        await Task.Delay(1000);
        ++Counter;
        saving = false;
        StateHasChanged();
    }
}
aleksamagicka commented 1 month ago

Similar issue here, have to double click it sometimes.

yenhanshih commented 2 weeks ago

Was about to open an issue and found this, thanks for opening it.

I believe this is because MudLoadingButton extends from MudBaseButton instead of MudButton. I'll do some tests later to confirm.

mckaragoz commented 2 weeks ago

Could you try with AutoDelay="0" parameter?

yenhanshih commented 2 weeks ago

@mckaragoz With AutoDelay="0" seems to work correctly now.