November Happy Hour will be moved to Thursday December 5th.

Dijt FilteringSelect and EpiServer rest store issues

Vote:
 

I have put together a widget which essentialy will allow users to select documents from external system and save links to them.

I have used a dijit FilteringSelect to achieve this together with Epi RestStore but I stumbled upon couple of issues.

  1. when there is value already set for the widget, (guid in my example), when dijit is making call to the RestStore, the call is like this: /modules/app/Stores/myreststore/a34f3fd8-8b9b-457f-9cde-56d8b886ff5b, and the value is not binded properly - the id is part of the path, and reststore controller treats it like null so I can't resolve the exact item for the store
  2. when I select value from the drop-down, it fails store the value with following error in console:
    Uncaught TypeError: Cannot read property 'toString' of undefined
        at Object._announceOption (widgets.js:2)
        at Object._selectOption (widgets.js:2)
        at Object.<anonymous> (dojo.js:15)
        at Object.advice (dojo.js:15)
        at Object._264 [as onChange] (dojo.js:15)
        at Object.onClick (widgets.js:2)
        at Object.<anonymous> (widgets.js:2)
        at dojo.js:15
        at Object.<anonymous> (widgets.js:2)
        at dojo.js:15

Model that I return from rest store:

    internal class Document
    {
        public Guid Id { get; set; }
        public string Title { get; set; }
        public string Author { get; set; }
        public DateTime ModificationDate { get; set; }
    }

Get method for the rest controller:

public RestResult Get(string query)
        {
            var results = Enumerable.Empty<Document>();
            if (string.IsNullOrEmpty(query) || query == "*")
            {
                results = documents;
            }
            else
            {
                query = query.Replace("*", String.Empty).ToLowerInvariant();
                if (Guid.TryParse(query, out var docId))
                {
                    results = documents.Where(doc => doc.Id == docId);
                }
                else
                {
                    results = documents.Where(doc =>
                            doc.Author.ToLowerInvariant().Contains(query) ||                            
                            doc.Title.ToLowerInvariant().Contains(query))
                        .Take(10);
                }
            }



            return Rest(results);
        }

Any help highly appreciated.

#222222
Apr 30, 2020 15:13
Vote:
 

If you're just using these values in a drop down list, do you need your document model?

Could be easier just to use an ISelectionQuery: https://world.episerver.com/documentation/developer-guides/CMS/Content/Properties/built-in-property-types/Built-in-auto-suggestion-editor/

#222630
May 08, 2020 17:34
Vote:
 

I need them for later as I would like to extend the rendering of the select box to contain some of them to help editor choose proper item.

#224002
Jun 09, 2020 9:35
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.