Skip to content

Commit

Permalink
DataGrid: prevent submitting form on Enter (#5897)
Browse files Browse the repository at this point in the history
* Datagrid - prevents submitting form on Enter in Filter if SubmitFormOnEnter is false. closes #5790

* Creates PreventDefaultSubmitBehavior private property

* Formating

---------

Co-authored-by: Mladen Macanovic <[email protected]>
  • Loading branch information
tesar-tech and stsrki authored Dec 13, 2024
1 parent 5350625 commit 55f6fdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 55f6fdc

Please sign in to comment.