Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

406
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda