Skip to content
Advertisement

How to have JS onpaste event work with Rails form?

I have a search form, and would like it so that when I paste something into the form, it automatically submits the form. I would also like to retain functionality so if I don’t paste something, and rather manually type it, that I have to press enter/search button for it to work.

Here is my form:

JavaScript

Could somebody tell me why this is not working?

Edit: I’ve tried Sercan Tırnavalı’s approach:

JavaScript

with no progress. Any other ideas/solutions are appreciated.

Advertisement

Answer

I believe you have the onpaste in the wrong place. Please try this:

JavaScript
Advertisement