Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
¿Cómo hacer que el evento JS onpaste funcione con el formulario Rails?

Tengo un formulario de búsqueda y me gustaría que cuando pegue algo en el formulario, lo envíe automáticamente. También me gustaría conservar la funcionalidad, de modo que si no pego algo, y lo escribo manualmente, tengo que presionar el botón Intro/Buscar para que funcione.

Aquí está mi formulario:

 <h1 class = "CustomerTitle">Search Tool</h1> <%= form_with url: "/support/search_res", class: "form", method: :get do |form| %> <%= form.text_field :query, class: "input", placeholder: "Search for a user..." %> <%= form.submit "Search", class: "submit_button", id: "pasteSubmit", onpaste: 'pasteAndGo()' %> <% end %> <script> function pasteAndGo() { document.getElementById('pasteSubmit').submit(); } </script>

¿Alguien podría decirme por qué esto no funciona?

Editar: he probado el enfoque de Sercan Tırnavalı:

 <h1 class = "CustomerTitle">Revuto Customer Support Tool</h1> <%= form_with url: "/support/search_res", class: "form", onpaste: 'pasteAndGo()', method: :get do |form| %> <%= form.text_field :query, class: "input", placeholder: "Search for a user..." %> <%= form.submit "Search", class: "submit_button" %> <% end %> <script> function pasteAndGo() { document.getElementsByClassName('form')[0].submit(); } </script>

sin progreso. Cualquier otra idea/solución es apreciada.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Creo que tienes el onpaste en el lugar equivocado. Por favor, intente esto:

 <h1 class = "CustomerTitle">Revuto Customer Support Tool</h1> <%= form_with url: "/support/search_res", class: "form", method: :get do |form| %> <%= form.text_field :query, class: "input", placeholder: "Search for a user...", onpaste: 'pasteAndGo()' %> <%= form.submit "Search", class: "submit_button" %> <% end %> <script> function pasteAndGo() { document.getElementsByClassName('form')[0].submit(); } </script>
about 4 years ago · Juan Pablo Isaza Report

0

Debe seleccionar el formulario y enviarlo, no el botón.

 <script> function pasteAndGo() { document.getElementsByClassName('form')[0].submit(); } </script>

También puede usar esta biblioteca js para este tipo de funcionalidad https://select2.org/data-sources/ajax

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!