4

I used the multilist with search and it works fine, but the results return the items and (Template name), and I want to return items name only without template name. is there any way to do that?

my query :

StartSearchLocation={C4B71DF5-3567-4458-8084-FBA73D5D1FB2}&Filter=+section_s:{C1D3DDBA-BD6F-4245-A5A7-2E3FED1D8B78}|+category_s:{39C14AB9-66F1-4CFC-B10C-BEC115F4086B}|+_language:en&TemplateFilter:{7D55B79F-E3F6-494C-8561-31E27D60B6F7}&SortField=__smallupdateddate[desc]

enter image description here

3 Answers 3

1

If I understand correctly , you need the results to be displayed without the template names (in brackets). Unfortunately, this is a OOTB feature in Sitecore Multilist search field type. You will need to override the field and use the below code.

public override string OutputString(Item item)  
{
     Item bucketItemOrParent = ItemExtensions.GetParentBucketItemOrParent(item);
     string str = bucketItemOrParent != null ? "- " + bucketItemOrParent.DisplayName : string.Empty;
     return string.Format("{0} ({1} {2})", item.DisplayName, item.TemplateName, str);
}

Code referenced from - https://blog.rauljimenez.co.uk/multlistfield-search/. Remove the ( ) in the String.Format link as per requirement.

1
  • Thank you, it's working fine with selected items, and still same problem with unselect items Commented Oct 22, 2019 at 8:52
4

Since this is the OOTB feature of the Sitecore so I will not recommend changing in it but if you just want to update the UI of the multilist with search field so that content author not see the template name then you can simply update the BucketList.js file located in \sitecore\shell\Controls\BucketList under your website. In this file you need to update the constructor for request success handler, see the commented line in below code -

self.SuccessHandler = function (multilist) {
    return function (request) {
        var response = eval(request.responseText);
        multilist.options.length = 0;
        multilist.removeClassName('loadingItems');

        var itemIdsHash = {};
        var reducedItems = [];
        var i;
        var item;
        for (i = 0; i < response.items.length; i++) {
            item = response.items[i];

            if (!itemIdsHash[item.ItemId]) {
                itemIdsHash[item.ItemId] = true;
                reducedItems[reducedItems.length] = item;
            }
        }

        for (i = 0; i < reducedItems.length; i++) {
            item = reducedItems[i];
            //multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name) + ' (' + item.TemplateName + (item.Bucket && (' - ' + item.Bucket)) + ')', item.ItemId);
            multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name), item.ItemId);
        }

        self.pageNumber = response.PageNumbers;
        self.currentPage = response.CurrentPage;
        $('pageNumber' + self.clientId).innerHTML = self.format(self.of, self.currentPage, self.pageNumber);
    };
};

You just need to remove + ' (' + item.TemplateName + (item.Bucket && (' - ' + item.Bucket)) + ')' line.

2
  • 1
    Many thanks, it's work fine 1oo % and solved my problem ... thank you Commented Oct 22, 2019 at 8:54
  • Consider source control this script, so that Sitecore upgrade should not break this feature. Commented Oct 22, 2019 at 10:24
0

You can also take a look at my project which uses a much better UI for searching (the same that you normally get with buckets): https://github.com/Barsonax/SitecoreSearchFields

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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