How do I use the Auto Suggest Selection Attribute?

  • Page Owner: Not Set
  • Last Reviewed: 2021-04-12

I'd like to know how to use the Auto Suggest Selection feature?


Answer

This feature is very similar to a Select Many or Select One attribute.

Create a selection Factory

Create a selection factory that implements the interface EPiServer.Shell.ObjectEditing.ISelectionQuery.

The two methods, GetItems, and GetItemByValue can pull from a cache if needed.

Example:

public class ExampleSelectionFactory : ISelectionQuery
{
    public ISelectItem GetItemByValue(string value)
    {
        throw new NotImplementedException();
    }

    public IEnumerable<ISelectItem> GetItems(string query)
    {
        throw new NotImplementedException();
    }
}

Add the attribute to your type

[AutoSuggestSelection(typeof(ExampleSelectionFactory ), AllowCustomValues = true)]

IMPORTANT NOTE: If you use AllowCustomFields = True any value in your ISelectItems will be ignored, and the Text will be used as the key.

Comments

  • Hi past me, In CMS 12 you also need to add [ServiceConfiguration(typeof(ISelectionQuery))] to your SelectionFactoryClass.