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

81
Views
Doesn't remove hide class after view render

In my Rails 5 app I've got a registration form where user is able to chose registration_type from dropdown list. When selects the Caregiver option, an additional field is shown on the form - it's handled by below registrant.js file:

$(document).on('focusout change', "#registrant_registration_attributes_registered_as", toggle_caregiver_fields_on_ready);

  function toggle_caregiver_fields_on_ready(){
    var caregiverSectionElement = $("#registrant_registration_attributes_registrant_id"),
      register_as = $("#registrant_registration_attributes_registered_as"),
      caregiver = (register_as.val() == 'caregiver');

    if (caregiver) {
      $('.patient-caregiver-section').removeClass('hidden');
      $('#patient-search-results').removeClass('hidden');
    } else {
        $('.patient-caregiver-section').addClass('hidden');
        $('#patient-search-results').addClass('hidden');
      }
  }

It works pretty well until the form throws an error which causes render :new from the controller create action, like below:

registrants_controller.rb

def create
  @registrant = Registrant.new(parse_post_params)

  if @registrant.save!
    #some logic (...)
    @registrant.add_special_status_to_history(current_login.user)
    @caregiver_patient.save! if @patient.present?
    redirect_to registrant_path(@registrant), notice: 'Registrant Added'
  else
    render :new
  end
end

After the :new page was rendered, the JS file didn't seem to work - in chrome console I dropdown is selected:

<select class="form-control required" aria-required="true" name="registrant[registration_attributes][registered_as]" id="registrant_registration_attributes_registered_as"><option value="">
  Please select
</option>
<option selected="selected" value="caregiver">Caregiver</option>
<option value="patient">Patient</option></select>

But the class patient-caregiver-section still has a hidden value:

<div class="patient-caregiver-section hidden">
          <div id="add-patient">
            <div class="form-group"><label class="non-bold-label pull-left" for="registrant_registration_attributes_patient_to_caregiver">
              Patient Added to Caregiver
            </label>
          </div>
        </div>
      </div>

How to force JS file to remove this class also when new action was rendered?

about 4 years ago · Juan Pablo Isaza
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!