1

While cleaning our contacts database, our users claimed that it would be beneficous to have the quick search bar remember the type of field to search in. In many cases it's helpfull to repeatedly search for zip codes or email addresses or stuff like that.

I had no luck finding information about accessing civi's session with js and therefore I wondered how to implement and decided to walk the extension way by feeding drupal with a cookie in my module's js file. What do you think?

CRM.$(document).ready(function () {
    /** 
     * Save quick search type on select
     */
    CRM.$('.crm-quickSearchField').click(function() {
        var label = CRM.$(this).text();
        var value = CRM.$('input', this).val();
        jQuery.cookie('quickSearchLabel', label);
        jQuery.cookie('quickSearchType', value);
    });

    /**
     * Set quick search type on load
     */
    var quickSearchType = jQuery.cookie('quickSearchType');
    if (quickSearchType) {
        var quickSearchLabel = jQuery.cookie('quickSearchLabel');
        var label = quickSearchLabel ? quickSearchLabel : "Suche";
        var value = quickSearchType;
        // These fields are not supported by advanced search
        if (value === 'first_name' || value === 'last_name') {
            value = 'sort_name';
        }
        KompiModsLib.radioSelect("input[name=quickSearchField]", value);
        CRM.$('#sort_name_navigation').attr({name: value, placeholder: label}).focus();
    }
});

And: would it be valuable to add it to the core?

1

That's a good idea. Here is a refinement of your patch that works it into core using localStorage, which is not CMS dependent.

https://github.com/civicrm/civicrm-core/pull/8485

| improve this answer | |

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.