Prevent Saving on Entering the Dialog Template KeyBoard Enter Key

Dear Syncfusion,
I want to prevent my dialog form from saving when some one presses  the Keyboard Enter key. According to my attached video, I want that when some one enters the Amount Paid and presses the Enter button, it should instead calculate the balance and display the amount in the Balance textbox but not Save and Close the Dialog Template; What is currently happening is that when someone presses the Enter key, the dialog form instead saves the record which is not what I want.

I will be glad for your response.



Attachment: PreventSaving_ec624640.rar

4 Replies 1 reply marked as answer

SJ Ssekamatte James April 28, 2021 11:13 AM UTC

To shed more light on my Query, when I add onkeypress in my grid events,
I get the error as shown in the screen shot attached. I have also attached my razor page where I want to disable the Enter Key button. 

Thank You

Attachment: onkeypress_2300511d.rar


RS Renjith Singh Rajendran Syncfusion Team April 29, 2021 09:14 AM UTC

Hi Ssekamatte, 

Greetings from Syncfusion support. 

By default, pressing Enter key will trigger the save action in Grid. So, based on your requirement, we suggest you to prevent the Save action using args.Cancel in OnActionBegin handler, based on the Enter key press in SfNumericTextBox. In the below code, we have prevented save using args.Cancel in OnActionBegin based on the @onkeydown event handler bound to SfNumericTextBox. 

Please refer and use the codes below, 

 
<SfGrid TValue="Order" ID="Grid" ...  >
    ... 
    <GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents> 
    <GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Dialog"> 
        <Template> 
            ... 
            <SfNumericTextBox TValue="double" ... ID="Freight" @bind-Value=@(((Order) context).Freight)  @onkeydown="onkeydown"  > 
            </SfNumericTextBox> 
 
        </Template> 
    </GridEditSettings> 
    ... 
</SfGrid> 

public bool flag = false;public void onkeydown(KeyboardEventArgs args){    if (args.Key == "Enter")    {        flag = true;    }}public async Task OnActionBegin(ActionEventArgs<Order> args){    if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save && flag)    {        flag = false;        args.Cancel = true;    }}
 
 
Query : when I add onkeypress in my grid events,I get the error as shown 
We suggest you to bind the onkeypress to SfGrid instead of GridEvents, as like the below code. 

<SfGrid TValue="Order" ... @onkeypress="KeyPressGrid">    ...</SfGrid>public void KeyPressGrid(){ }

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Marked as answer

SJ Ssekamatte James April 29, 2021 10:01 AM UTC

Hi Renjith R,

Thank You Very Much. The solution you shared has worked as I needed.


RS Renjith Singh Rajendran Syncfusion Team April 30, 2021 03:18 AM UTC

Hi Ssekamatte, 

We are glad to hear that your requirement is achieved. Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon