This is a migrated thread and some comments may be shown as answers.

Call custom js function after Enter key

3 Answers 25 Views
Form
This is a migrated thread and some comments may be shown as answers.
Frans
Top achievements
Rank 1
Veteran
Iron
Frans asked on 16 Mar 2021, 09:44 AM

Hi,

How can I achieve calling a custom javascript post call (jQuery) when a user enters the Enter key ? (actually independent of which field has the focus at that moment).
Just like with a classic button submit button, but instead calling a custom js function.

Martin

3 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 19 Mar 2021, 08:11 AM

Hi Frans,

As far as I understand you need to send an ajax post request when the 'Enter' key is pressed in the From. If this is the case, you could use the jQuery keydown event. You could check the pressed key. In case it is 'Enter' you could send the ajax request depending on the requirements. The example below demonstrates how an alert could be displayed in case 'Enter' key is pressed over a From with id "exampleForm".

$("#exampleform").on('keydown', function(e){            	
              if(e.key == 'Enter'){
              		alert('Enter key pressed in Form')
              }
})

This is demonstrated also in the Dojo linked here. As you will see if the Enter key is pressed on the input that is outside the From, no alert will appear.

I hope the provided suggestion suits your scenario. Let me know in case you have any further questions regarding the issue.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Frans
Top achievements
Rank 1
Veteran
Iron
answered on 19 Apr 2021, 09:01 AM

Hi Neli,

Thanks for your reply.
I understand this is a possible solution, but I would like to see this integrated in the Form component in a simpler way: 

Just with setting a property like 'bool SubmitOnEnterPress' or something, which simply gives this functionality out of the box in this Form control.

I want just a serverside solution, without hassle on the clientside with jQuery or css.

0
Neli
Telerik team
answered on 22 Apr 2021, 07:39 AM

Hello Frans,

When the Form is submitted the submit event is fired. However, the submit event will be triggered by pressing enter and also by clicking the submit button.

I am afraid that currently, the Form does not expose an event or a built-in option to configure that the Form could be submitted only on pressing 'Enter'. If you think that such enhancement would be a valuable addition I would suggest you log the idea in our official Feedback portal. Depending on the popularity the issue gain in the community, it could be considered for implementation in a future release.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Form
Asked by
Frans
Top achievements
Rank 1
Veteran
Iron
Answers by
Neli
Telerik team
Frans
Top achievements
Rank 1
Veteran
Iron
Share this question
or