I was wondering if there was some way to prevent the Enter key from submitting a Phoenix form. I would like the Enter key to be used for another event. Thank you!
Just don’t add a
<button> with the type
submit. Keep in mind that the default type of a
submit. Define it explicitly as
Thanks! For those that want to know you can just add this line as an option to Phoenix’s form_for :
<%= f = form_for @changeset, "#", id: "survey-form", phx_target: @myself, phx_change: "validate", phx_submit: "save", onkeydown: "return event.key != 'Enter';"%> # add this line
This will prevent the enter key from submitting the form.