blazormudblazor

MudDialog - how to execute default action button on return key press?


Considering this dialog below, how do I:

Adding ButtonType="ButtonType.Submit" doesn't seem to change anything.

<MudDialog IsVisible="true" Class="pa-4" >
    <DialogContent>
        <MudTextField @bind-Value="NewName" Label="Name" Variant="Variant.Outlined" />
    </DialogContent>
    <DialogActions>
        <MudButton Variant="Variant.Filled" OnClick="CloseCreateNewNameDialog">Cancel</MudButton>
        <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="CreateNewName">Create</MudButton>
    </DialogActions>
</MudDialog>

Thanks!


Solution

  • To make the create button submit you have to use the Form tag from MudBlazor : https://mudblazor.com/components/form#simple-form-validation

    <MudButton Variant="Variant.Filled" ButtonType="ButtonType.Submit" Color="Color.Primary" OnClick="CreateNewName">Create</MudButton>
    

    and to enable MudTextField to submit on return on keypress, use the EventCallBacks OnKeyPress