How to get a Multilist with Search field to not display referenced items' version and language?

家住魔仙堡 提交于 2019-12-23 15:33:41

问题


We are using Sitecore 7.2 to build a new application, and making extensive use of the new Multilist with Search field. We would like to be able to turn off display of the listed items' versions and languages in the list fields. How do we do this? Thank you.


回答1:


For sitecore 8 and above versions left part of multi-list field is filled by Ajax response from javascript file.

Below line needs to be modified your requirements, which is in

websiteRoot/sitecore/shell/Controls/BucketList/BucketList.js

multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name) + ' (' + item.TemplateName + (item.Bucket && (' - ' + item.Bucket)) + ')', item.ItemId);

For just item name or display name to be display do something like below:

multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name), item.ItemId);

Make sure you clear your browser cache after changing the .js file.




回答2:


I think you can do that by creating new field type which inherits 'Sitecore.Buckets.FieldTypes.BucketList' class.

Then overwrite 'OutputString' method with the following:

public override string OutputString(Item item4)
{
      Item parentBucketItemOrParent = item4.GetParentBucketItemOrParent();
      string str = (parentBucketItemOrParent != null) ? ("- " + parentBucketItemOrParent.get_Name()) : string.Empty;
      return string.Format("{0} ({1})", new object[] { item4.DisplayName, item4.TemplateName });
}

Now you will need to add this field type to Sitecore, go to 'Core' database, and duplicate this item:

/sitecore/system/Field types/List Types/Multilist with Search

In the new item, Clear 'Control' field, and fill 'Assembly' with your asembly name and 'Class' with your [Namespace.Classname]

Hope this will help

EDIT

You might need to override this function too, as this generate the JS function that parse the AJAX call when you try to search for a keyword:

    public override string JavaScriptOutputString(string clientId)
    {
        string[] strArrays = new string[] { "responseParsed", clientId, ".items[i].Name + ' (' + responseParsed", clientId, ".items[i].TemplateName + ')'" };
        return string.Concat(strArrays);
    }


来源:https://stackoverflow.com/questions/25331892/how-to-get-a-multilist-with-search-field-to-not-display-referenced-items-versio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!