Customize Advanced Search

Currently I've blacklisted a lot of elements in the advanced search as detailed at http://groups.google.com/group/omeka-dev/browse_thread/thread/16ca2d476c532399/e5178def4f04c2a2?hl=en%29&lnk=gst&q=customize+advnaced+search#e5178def4f04c2a2.

However I was wondering if there is a way to blacklist the groups "Item Type Metadata" and "Contribution Form" instead of every element in these groups. Basically I just want the advanced search options to be Title, Description, Subject, Date, Creator, and Publisher.

After noticing that the code linked above doesn't work in IE9 and has formatting issues in Chrome, I found that .remove() works better than .hide(). Also I figured out how to get block entire groups from showing. So now my code looks like:

<script type="text/javascript">
jQuery(document).ready(function () {
      var blackListGroups = new Array();
      blackListGroups[0] = "Item Type Metadata";
      blackListGroups[1] = "Contribution Form";
          for (var i = 0; i < blackListGroups.length; i++){
           jQuery("#advanced-0-element_id optgroup[label='" +
blackListGroups[i] + "']").remove();
      }
  });
</script> 

<script type="text/javascript">
jQuery(document).ready(function () {
      var blackListElements = new Array();
      blackListElements[0] = "Contributor";
      blackListElements[1] = "Coverage";
      blackListElements[2] = "Format";
      blackListElements[3] = "Identifier";
      blackListElements[4] = "Language";
      blackListElements[5] = "Relation";
      blackListElements[6] = "Rights";
      blackListElements[7] = "Source";
      blackListElements[8] = "Type";
          for (var i = 0; i < blackListElements.length; i++){
           jQuery("#advanced-0-element_id option[label='" +
blackListElements[i] + "']").remove();
      }
  });
</script>

This is a lot better than listing all 48 elements that I wanted to block from the advanced search drop down menus.

Thanks for posting this.

That previous snippet has been floating around for a while, and people seem drawn to it, so some optimization and reduction in size is definitely welcome.

If you're open to some further shrinking, I'd note that there's no reason you need to have two separate script blocks and two separate calls to jQuery(document).ready, and there's some additional jQuery functionality that you could take advantage of:

Incorrect code removed. See my later post for the corrected version.

Thanks, I went ahead and combined the script blocks and now I only call jQuery(document).ready once, but I kept the code the longer way. For whatever reason the truncated syntax didn't work on my site.

Oops, I made some stupid syntax errors. The corrected version follows:

jQuery(document).ready(function () {
    var blackListGroups = [
        "Item Type Metadata",
        "Contribution Form"
    ];
    var blackListElements = [
        "Contributor",
        "Coverage",
        "Format",
        "Identifier",
        "Language",
        "Relation",
        "Rights",
        "Source",
        "Type"
    ];

    jQuery.each(blackListGroups, function (index, value) {
        jQuery("#advanced-0-element_id optgroup[label='" + value + "']").remove();
    });

    jQuery.each(blackListElements, function (index, value) {
        jQuery("#advanced-0-element_id option[label='" + value + "']").remove();
    });
});

Thanks that works.