Monday, 20 August 2012

Omeka (again) Showing/hiding on Advanced Search

So we're getting rather clever with Omeka ( here at Otago  :) But we want MORE from the system without tinkering around with the engine of it (makes updates awkward). 

Our recent 'challenge' was to try and display ONLY the fields that we chose on the Advanced Search page (  There were a few notes on Omeka forums, and I did pick and choose some of it (notably, the 'blacklist' idea) but then it started tying my brain into knots.  Our resident genius then said 'why not create a whitelist?' Oh. Of course.

Resident genius came up with the following (I tweaked a couple of tiny things :)):

So, if you are struggling with customising your Advanced Search in Omeka, you are welcome to try this....

Step 1.  If it's not there already, take a copy of advanced-search.php from application/views/scripts/
items/advanced-search.php and put it in your items folder (credit to Will Riley on Omeka Dev for this -

Eg. themes/yourtheme/items/advanced-search.php

Step 2.  Decide what 'optgroup' and 'options' that you want to display. !important - it's easier/less time consuming to do this at Step 2. than later on .... trust me :)

Step 3.  Place the following at the BOTTOM of the advanced-search.php page:

<?php echo js('jquery'); ?>
<script type="text/javascript">
jQuery(document).ready(function () {
    <!--Part 1 - lets through the fields that you want showing up...-->
 whiteList = ['Abstract','Creator','Date','Description', 'Identifier', 'License', 'Medium', 'Publisher', 'Relation', 'Source', 'Spatial Coverage', 'Subject', 'Temporal Coverage', 'Title'];
    <!--Part 2 - blocks the optgroups that you DON'T want-->
    jQuery("[id='advanced-0-element_id-optgroup-Digital New Zealand']").remove();
    jQuery("[id='advanced-0-element_id-optgroup-Item Type Metadata']").remove();
    <!--Part 3 - is to take the optgroup that you DO want and head back up to the whitelisted fields and display them, remove all the other options-->
    jQuery.each($("[id='advanced-0-element_id-optgroup-Dublin Core'] option"), function(index, option) {
        if (jQuery.inArray(option.label,whiteList) == -1) {

Step 4.  In Part 1 add the fields you want to SHOW.
Step 5.  In Part 2 add the optgroups that you want to REMOVE.
Step 6.  In Part 3 add the optgroup that has the whitelisted fields that you want to SHOW.

Step 7. Test and debug :)



  1. Thanks for taking the time to post this code it works great. Is there a way to include fields from Item Type Metadata and Dublin Core? Step 3 only allows one set or the other.

  2. Edgar were you able to find a solution for this? If you were not able to, I will ask my colleagues to look into it.

  3. This comment has been removed by the author.