Skip to content

Instantly share code, notes, and snippets.

@Webbist-dev
Created December 16, 2014 12:44
Show Gist options
  • Save Webbist-dev/9b0c555f6c9a0e23aa2d to your computer and use it in GitHub Desktop.
Save Webbist-dev/9b0c555f6c9a0e23aa2d to your computer and use it in GitHub Desktop.
VSI contact form select changer
(function ($) { // passing Jquery $ into the function
// Define variable for our overall function
var Contact = {
// Define variables for the below function
contactItems: $('#block-views-studios-block .views-row'), // gets the container for each sidebar idem
selectDropdown: $( "#edit-submitted-studio"), // gets us the select element
// Initialising functions (Function written below)
init: function(){
this.contactItemChanger();
},
// Initialising functions (for on select change)
initActions: function() {
that = this // Sets THIS at the level we want, so we can use it within our change function
this.selectDropdown.change(function() {
that.contactItemChanger(); // initialise function on change of select dropdown (reruns the below function)
});
},
// The fucntion to show/hide sidebar blocks based on value in the select
contactItemChanger: function(){
this.contactItems.hide(); // Hide all the sidebar blocks
selectValue = $( "#edit-submitted-studio" ).val(); // gets the value in the select dropdown
this.contactItems.each(function(){ // on each view row
title = $(this).find('.field-name-title').text(); // we find the title within the view row and get the text value (to compare with the select value)
if(selectValue == title) { // here we compare the values
$(this).show(); // if the values match using this we show only the view row we need
}
});
}
};
// Drupal Behavior the same as running on dom ready but also on ajax page change
Drupal.behaviors.contact = {
attach: function (context, settings) {
Contact.init(); // run our initial function
Contact.initActions(); // run our change event function
}
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment