Entering an input key is not a rails issue, but an HTML / JS issue
Rails is a backend (lives on the server); Client-side HTML / JS (real-time in the browser) - they determine which features are enabled / disabled
I would go around your problem like this:
$('form').on('keypress', e => { if (e.keyCode == 13) { return false; } });
And if you use Turbolinks:
$(document).on('turbolinks:load', () => { $('form').on('keypress', e => { if (e.keyCode == 13) { return false; } }); });
Useful link: How to prevent the ENTER key from being pressed when submitting a web form?
Richard Peck
source share