Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

405
Vistas
Ruby on Rails show field when checkbox checked WITHOUT JAVASCRIPT

I feel like I'm going insane. This seems so simple but somehow I cannot find an answer on the internet.

I have a form with a checkbox in it. If the checkbox is checked, I want to display an input field. How do I do that in Ruby on Rails without Javascript? All the solutions I saw were with Javascript for like 9 years old.

= simple_form_for(@register) do |f|

  .form-inputs
    = f.input :first_name
    = f.input :last_name, required: true
    = f.check_box :special_request
    = f.label :special_request

# and now here should be the if-else statement that should go something like this
   if :special_request.checked?
    = f.input :request

But I have yet to find out how exactly this is supposed to be implemented. It seems like the easiest task, but I have yet to find an answer. Also, no matter if the checkbox is checked or not, the value is always 1 when I look at it in with inspect.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The closest you'll get to this is the "Checkbox Hack"

.control-me {
  display: none;
}

#toggle:checked ~ .control-me {
  display: block;
}
<input type="checkbox" id="toggle">
<div class="control-me">
  <input type="text">
</div>

Adapted from:

https://css-tricks.com/the-checkbox-hack/

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda