How to submit form when pressing enter

Hi,

I presently have a form which has several inputs and a button. The button is configured with a submit behavior and when pressed, the logic in “On Submit Event” for the form is executed.

If I want to do the same when the enter key is pressed in the inputs, then I use the “On Key Down Event” and check if the Key Code = 13 and if so execute the same logic.

The sad thing is this logic has to be copied from the form’s “On Submit Event”. What I am looking for is to submit the form when pressing enter. But I have not found this block. And when trying to write a custom code block with formComponent.el.submit() then the form is submitted but the whole application reloads (!)

Could you suggest a way to do this ? Thanks !

Hi Nicolas Remy!

Submit should be triggered by default on the Enter key. I just checked and everything works correctly.

Regards,
Alexander

1 Like

Thanks. Good to know !

Hello everyone, here’s the opposite question: we have a form which contains a sub-component which does something when the user hits “Enter” (sort of like a form within a form, user creates a new term in our application while filling out the parent form).

Our problem is that the Enter key triggers the parent form submit. Is there a way to prevent this? We need the user to explicitly click “Submit” button on the parent form, and NOT have the submit be triggered when user hits “Enter” anywhere on the form.

Nevermind my previous question, found the answer in another support topic:

To disable the “submit form when Enter key is pressed” behaviour, don’t have any buttons on the form with “Submit” behaviour. Instead, make the button which is supposed to submit the form have “Default” behavior and wire it up to submit the form in its “on Click” event.

1 Like