Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid: prevent submitting form on Enter #5897

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Source/Extensions/Blazorise.DataGrid/DataGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
@paginationFragment
}
<Form>

@if ( IsCellEdit && ( CommandColumn is null || !CommandColumn.SaveCommandAllowed ) )
@if ( PreventDefaultSubmitBehavior )
{
//Disable the default form behaviour where pressing enter submits the form and posts the page which is not expected in typical SPA fashion.
<Button Type="ButtonType.Submit" PreventDefaultOnSubmit Disabled Display="Display.None"></Button>
}

Expand Down
7 changes: 7 additions & 0 deletions Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,13 @@ internal bool MultiSelect
/// </summary>
protected bool PopupVisible => EditMode == DataGridEditMode.Popup && EditState != DataGridEditState.None;

/// <summary>
/// Disable the default form behaviour where pressing enter submits the form and posts the page which is not expected in typical SPA fashion.
/// </summary>
private bool PreventDefaultSubmitBehavior =>
( IsCellEdit && ( CommandColumn is null || !CommandColumn.SaveCommandAllowed ) )
|| ( Filterable && !SubmitFormOnEnter ); //prevents submits on Enter within Filter input

/// <summary>
/// Defines the size of popup dialog.
/// </summary>
Expand Down
Loading