Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Created May 31, 2010 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahhendrix/420261 to your computer and use it in GitHub Desktop.
Save noahhendrix/420261 to your computer and use it in GitHub Desktop.
<%= semantic_form_for (@activity ||= Activity.new) do |f| %>
<%= f.inputs :name => "Quickly record what you did" do %>
<%= f.input :date, :selected => Date.today, :order => [:month, :day, :year] %>
<%= f.input :category, :collection => [ "Office", "Personal", "Sales" ], :label => "Type", :input_html => { :class => "change-form-options" } %>
<%= f.inputs :rel => "Sales" do %>
<%= f.input :contact_id, :as => :string %>
<% end %>
<%= f.input :notes %>
<%= f.inputs :rel => "Sales Office" do %>
<%= f.input :outcome, :collection => [ "In the bag", "Will get them with some effort", "50-50 chance no matter what we do", "Probably won't get their business", "Waste of time" ] %>
<%= f.input :next_steps %>
<% end %>
<% end %>
<%= f.submit %>
<% end %>
// In some forms the fields change based on change in select
$('select.change-form-options').change(function(event){
$select = $(this); //cache the select input
value = $select.val(); //save the value in the input
$parent_form = $select.parents("form"); //get/cache the form
$optional_fieldsets = $parent_form.find("fieldset[rel]");
$optional_fieldsets.hide().filter("[rel~="+value+"]").show(); //~= contains word in attribute somewhere
}).change();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment