Xperience 13 Refresh 1 Object Selector and General Selector Not Working

Julian Piane asked on March 28, 2021 20:29

I would like to have a property on a widget that allows the user to select multiple categories. I believed that the GeneralSelector or ObjectSelector introduced in Xperience 13 Refresh 1 would have been perfect for this, however, neither appear to be working for me.

My initial attempt involved simply adding the Object Selector to the Widget Properties like below and linking it to the "cms.category" object type:

    [EditingComponent(ObjectSelector.IDENTIFIER,
    Order = 5,
    Label = "Selected Categories")]
[EditingComponentProperty(nameof(ObjectSelectorProperties.ObjectType), "cms.category")]
[EditingComponentProperty(nameof(ObjectSelectorProperties.MaxItemsLimit), 0)]
public IEnumerable<ObjectSelectorItem> BlogCategories { get; set; } = Enumerable.Empty<ObjectSelectorItem>();

When I add this to my properties, the new field is available in the editor, however it is empty and clicking either the "Clear" or "See all" buttons does nothing.

I figured this must be an issue with how the data was being pulled, so I tried implementing this using the General Selector. I added the General Selector to my Widget Properties like shown below:

        [EditingComponent(GeneralSelector.IDENTIFIER,
        Order = 4,
        Label = "Selected General Categories")]
    [EditingComponentProperty(nameof(GeneralSelectorProperties.DataProviderType), typeof(CategoriesDataProvider))]
    [EditingComponentProperty(nameof(GeneralSelectorProperties.MaxItemsLimit), 0)]
    public IEnumerable<GeneralSelectorItem> Categories { get; set; } = Enumerable.Empty<GeneralSelectorItem>();

And I defined my DataProvider as such:

    public class CategoriesDataProvider : IGeneralSelectorDataProvider
{
    public async Task<GeneralSelectorSelectListItems> GetItemsAsync(string searchTerm, int pageIndex, CancellationToken cancellationToken)
    {
        // Defines a query that loads all email feeds on the current site
        ObjectQuery<CategoryInfo> query = CategoryInfoProvider.GetCategories().OnSite(SiteContext.CurrentSiteName);  

        if (!String.IsNullOrEmpty(searchTerm))
        {
            // Applies the search term to the database query
            query.WhereContains("CategoryDisplayName", searchTerm);
        }

        // Ensures paging of items
        query.Page(pageIndex, 50);

        IEnumerable<CategoryInfo> items = await query.GetEnumerableTypedResultAsync(cancellationToken: cancellationToken);

        // Formats and returns the data
        return new GeneralSelectorSelectListItems
        {
            // Transforms the data into the correct format
            Items = items.Select(GetSelectedListItem),
            // Indicates whether there is another page of incoming results
            NextPageAvailable = query.NextPageAvailable
        };
    }

    public Task<IEnumerable<GeneralSelectorSelectListItem>> GetSelectedItemsAsync(IEnumerable<GeneralSelectorItem> selectedValues, CancellationToken cancellationToken)
    {
        // Creates a list containing identifiers of the selected objects
        var identifiers = selectedValues.Select(x => x.Identifier).ToList();

        ObjectQuery<CategoryInfo> query = CategoryInfoProvider.GetCategories()
                                        .OnSite(SiteContext.CurrentSiteName)
                                        .WhereIn("CategoryDisplayName", identifiers);
        IEnumerable<CategoryInfo> items = query.GetEnumerableTypedResult();

        // Orders the retrieved items by their display name
        IOrderedEnumerable<CategoryInfo> orderedItems = items.OrderBy(o => identifiers.IndexOf(o["CategoryDisplayName"].ToString()));

        // Transforms the data into the correct format
        return Task.FromResult(orderedItems.Select(GetSelectedListItem));
    }

    private GeneralSelectorSelectListItem GetSelectedListItem(CategoryInfo category)
    {
        return new GeneralSelectorSelectListItem
        {
            // Sets the string used in the selector interface
            Text = category.CategoryDisplayName,
            Value = new GeneralSelectorItem { Identifier = category.CategoryDisplayName }
        };
    }
}

However, yet again, despite the new field being available in the editor, it is empty and clicking either the "Clear" or "Show all" buttons does nothing. Below is a screenshot of what I see when attempting to use these selectors.

Image Text

I believe I have followed documentation exactly, so I am curious why this feature is not working for me. No relevant logs could be found and no errors are output to the console or the event log. I would also like to note that no breakpoints within CategoriesDataProvider.cs are being hit. Perhaps I ran the upgrade incorrectly? Thank you for any help.

Recent Answers


Lukáš Gancarčík answered on April 8, 2021 13:52

Hi Julian,

I had similar issue before - however after I rebuild the solution and cleared the browser cache it started to work. Could you please therefore try to rebuild the solution and clear the browser cache?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.