From 55f6fdca5ecb186c9fe001b695917ab8b35fbcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tesa=C5=99?= <33880579+tesar-tech@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:54:39 +0000 Subject: [PATCH] DataGrid: prevent submitting form on Enter (#5897) * Datagrid - prevents submitting form on Enter in Filter if SubmitFormOnEnter is false. closes #5790 * Creates PreventDefaultSubmitBehavior private property * Formating --------- Co-authored-by: Mladen Macanovic --- Source/Extensions/Blazorise.DataGrid/DataGrid.razor | 4 +--- Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Extensions/Blazorise.DataGrid/DataGrid.razor b/Source/Extensions/Blazorise.DataGrid/DataGrid.razor index 784834d4cc..7f8bb013c1 100644 --- a/Source/Extensions/Blazorise.DataGrid/DataGrid.razor +++ b/Source/Extensions/Blazorise.DataGrid/DataGrid.razor @@ -11,10 +11,8 @@ @paginationFragment }
- - @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. } diff --git a/Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs b/Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs index b34ddec160..704ee6fd83 100644 --- a/Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs +++ b/Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs @@ -3135,6 +3135,13 @@ internal bool MultiSelect /// protected bool PopupVisible => EditMode == DataGridEditMode.Popup && EditState != DataGridEditState.None; + /// + /// Disable the default form behaviour where pressing enter submits the form and posts the page which is not expected in typical SPA fashion. + /// + private bool PreventDefaultSubmitBehavior => + ( IsCellEdit && ( CommandColumn is null || !CommandColumn.SaveCommandAllowed ) ) + || ( Filterable && !SubmitFormOnEnter ); //prevents submits on Enter within Filter input + /// /// Defines the size of popup dialog. ///