Save form when press "Enter" Keyboard

Hello,
I'm currently facing an issue. When I fill in form using @Html.BeginForm, I want to make a confirmation dialogue pop up before it save the data. I can do it by clicking the save button using mouse control. The problem is, if I just press enter keyboard, it will automatically save without displaying the confirmation dialog first. How can I make the confirmation dialog pop up if I press the enter keyboard?
Thank you

1 Reply 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team July 10, 2020 12:45 PM UTC

Hi Ahmad, 


Greetings from Syncfusion support. 


We checked the reported requirement. We have prepared the custom sample based on the requirement. Cancel the form submit in the button submit event using preventDefault(). If you click the save button in the dialog call the submit method for formelement. Otherwise hide the dialog. Refer to the code below, 

function onFormSubmit(e) { 
        e.preventDefault();  
        var confirm = document.getElementById("confirmationDialog").ej2_instances[0]; 
        confirm.show(); 
    } 
function dlgSaveClick() { 
        var dialogObj = document.getElementById("confirmationDialog").ej2_instances[0]; 
        var formStatus = formObj.validate(); 
        document.getElementById('form1').submit(); 
        dialogObj.hide(); 
    } 
    function dlgCancelClick(e) { 
        var dialogObj = document.getElementById("confirmationDialog").ej2_instances[0]; 
        dialogObj.hide(); 
    } 




Regards, 
Sevvandhi N 


Marked as answer
Loader.
Up arrow icon