Skip to content

Instantly share code, notes, and snippets.

@etech0
Last active March 29, 2016 20:16
Show Gist options
  • Save etech0/16d63ab805c4390b9a133213545cbe34 to your computer and use it in GitHub Desktop.
Save etech0/16d63ab805c4390b9a133213545cbe34 to your computer and use it in GitHub Desktop.
tripFilter = function () {
var tripClass = '.hotel-trip select',
hotelClass = '.hotel-name select',
cityClass = '.city-date select',
unusedClass = '.unused-options select';
var tripSelect = jQuery(cityClass), //used to be tripClass
trip = tripSelect.val(), //figure out which trip they're going on
hotelSelect = tripSelect.parents('form').find(hotelClass); //set the var for the dropdown box for Hotel Room Option
if (trip !== undefined && trip !== "") {
if (trip === "none"){ //if no trip, show no options
jQuery(hotelClass+" > option").each(function() {
jQuery(this).clone().appendTo(unusedClass);
jQuery(this).remove();
});
} else { //if it has a trip
tripnum = trip.match(/JWRP (\w*) /)[1]; //set tripnum to be the # of that trip
// GET ALL OPTIONS THERE
jQuery(unusedClass+" > option").each(function() { //for each option in the Unused box
jQuery(this).clone().appendTo(hotelClass); //move it to this trip (all)
jQuery(this).remove();
});
// REMOVE BAD OPTIONS
jQuery(hotelClass+" > option").each(function() { //for each option in the Hotel box
hotelMatch = jQuery(this).val().match(/(\w*) /); //pull out the tripnum from the option
if(jQuery(this).val() != "Other|0"){ // if it's not Other
if (hotelMatch === null || hotelMatch[1] != tripnum){ //if this option doesn't match this trip
jQuery(this).clone().appendTo(unusedClass); //get rid of this option
jQuery(this).remove();
};
}else{
//jQuery(this).appendTo(hotelClass); //if the option is Other, keep it
};
});
//jQuery(hotelClass + 'option[value="Other|"]').insertAfter(hotelClass + 'option:last-child'); //move the Other option to the end
if (jQuery(hotelClass).val() == '' )
{
jQuery(hotelClass).val(jQuery(hotelClass + "option:first").val()); //select the first option for Hotels
};
jQuery(unusedClass).val(jQuery(unusedClass + "option:first").val());//select the first option for Unused (these 2 prevent submission errors)
}
}
}
jQuery(document).bind('gform_post_render', function(){
jQuery('.city-date select').change(function(){ //used to be .hotel-trip select
tripFilter()
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment