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

404
Views
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 answers
Answer question

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 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!