Skip to content

Instantly share code, notes, and snippets.

@EmmaB
Last active August 29, 2015 13:56
Show Gist options
  • Save EmmaB/8885838 to your computer and use it in GitHub Desktop.
Save EmmaB/8885838 to your computer and use it in GitHub Desktop.
// view file
= f.input :use_metadata_fields, :label => "Choose one...", :as => :select, :collection => [["Fill in detailed metadata fields","1"], ["Use a default profile","0"]], :input_html => {:id => :use_metadata_fields, :class => 'input-small'}
#default_fields // a hash sign is the haml for div id
= f.input :default_fields, :as => :select, :collection => @defaults, :method_label => :description
#metadata_fields
= f.input :price
= f.input :pub_date
= f.input :imprint
= f.input :category
= f.input :bic
= f.input :format
= f.input :pages
= f.input :blurb
= f.input :selling_points
// jquery file
$(document).ready(function () {
toggler(); //first set things up properly on page load
//this will call the toggler function every time the selection value of the use_metadata_fields field changes
$("#use_metadata_fields").change(function () {
toggler();
});
});
function toggler() {
if ($("#use_metadata_fields").val() == "1") // of course jquery's comparative operator is a 'double equals'. facepalm.
{
$("#metadata_fields").show();
$("#default_fields").hide();
} // and of course each line has a semi-colon at the end and both lines need to be wrapped in curly braces. sigh.
else
{
$("#metadata_fields").hide();
$("#default_fields").show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment