function toggle_options(element_name) {
  const cluster = current_cluster_capitalized();
  const search = "#" + element_name + " option"
  const options = $(search);

  options.each(function(_i, option) {
    // the variable 'option' is just a data structure. it has no attr, data, show
    // or hide methods so we have to query for it again
    let option_element = $(search + "[value='" + option.value + "']");
    let data = option_element.data();
    let show = data["optionFor" + cluster];

    if(show == false) {
      option_element.hide();

      if(option_element.prop('selected')) {
        option_element.prop('selected', false);

        // when de-selecting something, the default is to fallback to the very first
        // option. But there's an edge case where you want to hide the very first option,
        // and deselecting it does nothing.
        if(option_element.next()){
          option_element.next().prop('selected', true);
        }
      }
    } else {
      option_element.show();
    }
  });
}
/**
 * Hide or show options of an element based on which cluster is
 * currently selected and the data-option-for-CLUSTER attributes
 * for each option
 *
 * @param      {string}  element_name  The name of the element with options to toggle
 */
Hide or show options of an element based on which cluster is
currently selected and the data-option-for-CLUSTER attributes
for each option

@param      {string}  element_name  The name of the element with options to toggle
Hide or show options of an element based on which cluster is currently selected and the data - option - for - CLUSTER attributes for each option @param { string } element_name The name of the element with options to toggle
function toggle_options(element_name) {
  const cluster = current_cluster_capitalized();
  const search = "#" + element_name + " option"
  const options = $(search);
  options.each(function(_i, option) {
    let option_element = $(search + "[value='" + option.value + "']");
    let data = option_element.data();
    let show = data["optionFor" + cluster];
    if(show == false) {
      option_element.hide();
      if(option_element.prop('selected')) {
        option_element.prop('selected', false);
        if(option_element.next()){
          option_element.next().prop('selected', true);
        }
      }
    } else {
      option_element.show();
    }
  });
}
function toggle_options ( element_name ) { const cluster = current_cluster_capitalized ( ) ; const search = "#" + element_name + " option" const options = $ ( search ) ; options . each ( function ( _i , option ) { let option_element = $ ( search + "[value='" + option . value + "']" ) ; let data = option_element . data ( ) ; let show = data [ "optionFor" + cluster ] ; if ( show == false ) { option_element . hide ( ) ; if ( option_element . prop ( 'selected' ) ) { option_element . prop ( 'selected' , false ) ; if ( option_element . next ( ) ) { option_element . next ( ) . prop ( 'selected' , true ) ; } } } else { option_element . show ( ) ; } } ) ; }
Hide or show options of an element based on which cluster is
 currently selected and the data-option-for-CLUSTER attributes
 for each option
Hide or show options of an element based on which cluster is currently selected and the data - option - for - CLUSTER attributes for each option
// the variable 'option' is just a data structure. it has no attr, data, show // or hide methods so we have to query for it again // when de-selecting something, the default is to fallback to the very first // option. But there's an edge case where you want to hide the very first option, // and deselecting it does nothing.