Dependent Form Fields

#17 Dependent Form Fields
9/2/2015

Summary

Using unobtrusive javascript, we can hide certain fields on forms based on the selected values of other fields.
1
rails javascript view

Summary

Gemfile    gem 'jquery-turbolinks'
    gem 'dependent-fields-rails'
application.js    //= require jquery.turbolinks
    //= require underscore
    //= require dependent-fields

    $(document).ready(function() {
      DependentFields.bind()
    });
_form.html.erb    <%= f.input :extended_profile, id: 'user_extended_profile' %>
    <%= content_tag :div, class: 'js-dependent-fields', data: { 'checkbox-id': 'user_extended_profile', 'checkbox-value': 'true'} do %>
      <%= f.input :twitter_handle %>
      <%= f.input :facebook_handle %>
      <%= f.input :github_handle %>
    <% end %>