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.
- 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
- 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.