locked
WinJS Autosuggest dropdown not showing

    Question

  • I am trying to get autosuggest to work, I can see in the consolelog that suggestionCollection is populated with data, but the drop down never appears.

    any help thanks

    $(document).ready(function () {
        var asbBox = document.getElementById("asbId");
        var asb = new (<any>WinJS.UI).AutoSuggestBox(asbBox);
        asb.placeholderText = "Enter Postcode or Location";
        asb.searchHistoryDisabled = "true";
        asbBox.addEventListener("suggestionsrequested", suggestionsRequestedHandler);
        asbBox.addEventListener("querysubmitted", querySubmittedHandler);
        WinJS.UI.processAll();
    });
    
    function suggestionsRequestedHandler(eventObject: any) {
        var queryText = eventObject.detail.queryText,
            query = queryText.toLowerCase(),
            suggestionCollection = eventObject.detail.searchSuggestionCollection;
        if (query.length > 2) {
            var p = new RemoteData().postData("http://api.xxxxx.com.au/api/LocationViews/SearchLocationViews", { query: query });
            p.done(
                function completed(request: any) {
                    var obj = JSON.parse(request.response);
                    obj.forEach(function (item: any) {
                        console.log(suggestionCollection)
                        suggestionCollection.appendQuerySuggestion(item.FormatedLocation);
                    });
                    WinJS.UI.processAll();
    
                },
                function error(request: any) {
                    console.log(request);
                });
        }
    }


    Alan Mosley - ThatsIT Solutions

    Wednesday, April 1, 2015 5:11 PM

Answers

All replies

  • solved had to wrap code in a promise because it is async
    see "args.detail.setPromise(WinJS.Promise.then(null,"  on page https://msdn.microsoft.com/en-us/library/windows/apps/dn301954.aspx

    Alan Mosley - ThatsIT Solutions


    • Marked as answer by Alan Mosley Thursday, April 2, 2015 5:32 AM
    • Edited by Alan Mosley Thursday, April 2, 2015 9:01 AM
    Thursday, April 2, 2015 5:32 AM
  • Hi Alan,

    Nice to see the problem solved, you may also share the solution with us for other communities who meet the same problem.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 2, 2015 8:13 AM
    Moderator