i'm trying use jquery different parts or form revealed depending on radio button clicked. used jsfiddle working on plain vanilla form first , seemed fine when apply same code logic rails app uses simple_form gem nothing seems work.
see code below
$("input[type=radio]").click(function(){ if ($('input[name=usertype]:checked').val() == "user a") { $("#one").slidedown("fast"); $("#two").slideup("fast"); $("#three").slideup("fast"); $("#four").slideup("fast"); } if ($('input[name=usertype]:checked').val() == "user b") { $("#two").slidedown("fast"); $("#one").slideup("fast"); $("#three").slideup("fast"); $("#four").slideup("fast"); } if ($('input[name=usertype]:checked').val() == "user b") { $("#three").slidedown("fast"); $("#two").slideup("fast"); $("#one").slideup("fast"); $("#four").slideup("fast"); } if ($('input[name=usertype]:checked').val() == "user b") { $("#four").slidedown("fast"); $("#three").slideup("fast"); $("#two").slideup("fast"); $("#one").slideup("fast"); } }); <%= simple_form_for(resource, :as => resource_name, :html => { :class => 'form-horizontal' }, :url => registration_path(resource_name)) |f| %> <%= f.input :email, placeholder: 'example@domain.com' %> <%= f.input :username %> <%= f.input :usertype, label: 'which best describes you', :input_html => {:name => "usertype"}, :collection => ["user a", "user b", "user c", "user d"], as: :radio_buttons %> <ul id="one"> <li><%= f.input :dob, label: 'date of birth', as: :date, start_year: date.today.year - 90, end_year: date.today.year - 16, order: [:day, :month, :year] %></li> </ul> <ul id="two"> <li><%= f.input :launchedin, label: 'year club launched', as: :date, start_year: date.today.year - 300, end_year: date.today.year, discard_day: true, discard_month: true, order: [:year] %></li> </ul> <ul id="three"> <li><%= f.input :category, :collection => ["football", "golf", "tennis", "rugby"], prompt: 'choose sport' %> </ul></li> <ul id="four"> <li><%= f.input :bio, label: 'tell you', hint: 'maximum 300 characters' %></li> </ul> <%= f.input :password %> <%= f.input :password_confirmation %> <div><%= f.submit "register", :class => 'btn btn-primary' %></div> <% end %>
have come @ least 4 version of jsfiddle work, none work on rails app.
would appreciate on this, stress ball can take :-)
many thanks
kieran
assuming use rails 3.2 or newer, ...try to:
- check if js generated app correct (it contains code) (source code of html page)
- did chance run
rake assets:precompile
before applying this? rails may picking precomiled version of application.js . if tryrake assets:clean
- make sure jquery loaded before file have js/coffeescript logic
- make sure use
$(document).ready ->
in js/coffeescript file handling logic
Comments
Post a Comment