7

In the CiviCRM global menu there is a nice search box on the left. This box allows for targeting specific fields via radio buttons in a dropdown, like this:

CiviCRM global menu search box

Is it possible to remove or change the fields that appear here?

Can custom contact fields be added to these options?

7

The quick answer is "no."

For some back-story, that feature was contributed (circa 4.3) by a volunteer from the community who was enough of a coder to be able to get it to work, but not really a CiviCRM architect. His implementation was done by hard-coding that list of fields directly into the template.

The result of his good-faith effort is that:

  • We have the feature (which IMO is a step up from previously not having it).
  • It's not flexible or extensible.

I've been thinking that it would be a great little project for someone to add a setting to the "display preferences" screen that would allow you to enable/disable fields from that list. Searchable custom fields could be included.

If anyone is interested in taking this on, let me know in the comments and I'm more than happy to help you get started.

  • Great, thank you. I actually scanned the "display preferences" page over and over in vein looking for some checkboxes for the search dropdown. Your answer at least lets me know it's not there (but that I should consider implementing it). – Link Swanson Mar 31 '15 at 14:14
  • This looks like a functionality regression starting from 4.5. Previous to this version with a "simple" custom development using hook_civicrm_contactListQuery you were able to adapt quick search to your needs. In my case, filtering by a custom field. I will be looking a quick workaround to get this working again (maybe an extension, cause I need it for CiviCRM 4.5.x). Coleman any tip will be welcome. Tx – luciano_s Jul 20 '15 at 15:07
  • @LucianoSpiegel the contents of that list has never been alterable via hooks, per my answer above. But if you want to modify the behavior of the query, see this answer. – Coleman Jul 20 '15 at 16:21
5

As Coleman said, no, for adding fields, but we removed certain fields for our setup with jQuery so our users wouldn't mis-click.

EDIT: I went back to look at the code, and I remembered that we tried removing the fields with simple jQuery .hide() or .remove(), but realized that the standard classes we were trying to use were used elsewhere so it did more damage than good. In trying to use something like a nth-child selector on the li, we ran into trouble as well, though I can't remember what exactly.

We ended up going the custom tpl route by creating a copy of templates/CRM/common/navigation.js.tpl and placing it in our custom templates directory and commenting out of the "li"'s that we didn't want. Beginning around line 40:

<!-- <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="contact_id" name="quickSearchField">{ts}CiviCRM ID{/ts}</label></li> -->
<!-- <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="external_identifier" name="quickSearchField">{ts}External ID{/ts}</label></li> -->

Looking back at it now, it would have been better to slog through and find the right combination of selectors with jQuery. Perhaps something like this:

CRM.$(function($) {
    $('#civicrm-menu #crm-qsearch ul li:nth-child(3)').hide();
});
  • This answer would be even better if you supplied example code for doing so :) – Coleman Apr 9 '15 at 15:13
  • @Allen Hutchinson if you could dig out that jquery and share here, I'm sure many would be interested in seeing it. – Link Swanson Apr 9 '15 at 16:00
  • Thanks Coleman and @LinkSwanson ! I edited my answer and put in some example code. Provided with a grain of salt. :) – Allen Hutchison Apr 9 '15 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.