none
Multiple AutoSuggests on 1 form RRS feed

  • Question

  • I would like to have auto suggest attached to 2 different fields on my entry form. The first auto suggest code block below works. The definition of 2nd errors out. How do I accomplish this task?

            function GetMap() {
    
                 Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', {
                    callback: function () {
                        var manager = new Microsoft.Maps.AutosuggestManager({
                            placeSuggestions: true
                        });
                        manager.attachAutosuggest('#Location', '#searchBoxContainer', suggestionSelected);
                    },
                    errorCallback: function (msg) {
                        alert(msg);
                    }
                });
    
                Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', {
                    callback: function () {
                        var manager2 = new Microsoft.Maps.AutosuggestManager({
                            placeSuggestions: true
                        });
                        manager2.attachAutosuggest('#Location2', '#searchBoxContainer2', suggestionSelected2);
                    },
                    errorCallback: function (msg) {
                        alert(msg);
                    }
                });
    
            }


    Friday, April 12, 2019 2:00 PM

All replies

  • Hi DDL19,

    Can you tell me more about your scenario?  We do have a form filling sample at https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Autosuggest/Fill%20Address%20Form%20with%20Autosuggest.html

     that fills in the related fields for an address.  Is this what you are trying to do?  Why do you require two search items?

    Sincerely,

    IoTGirl

    Friday, April 12, 2019 3:54 PM
    Owner
  • I have 3 different address boxes to be entered on the same form. I need the lookup behavior on all 3....

    Location #1

    Searchbox

    Auto fill fields below...

    address

    City 

    State

    Location #2

    Search box

    Autofill fields below...

    Address

    City

    State

    Friday, April 12, 2019 4:00 PM
  • Hi DDL19,

    My guess would be that you don't need to load the module more than once. 

    Sincerely,

    IoTGirl

    Friday, April 12, 2019 7:32 PM
    Owner
  • This code would not work either with a failed to load message... Could you give me some sample code 
            function GetMap() {
    
                 Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', {
                    callback: function () {
                        var manager = new Microsoft.Maps.AutosuggestManager({
                            placeSuggestions: true
                        });
                        manager.attachAutosuggest('#Location', '#searchBoxContainer', suggestionSelected);
                        manager.attachAutosuggest('#Location2', '#searchBoxContainer2', suggestionSelected2);
                     },
                    errorCallback: function (msg) {
                        alert(msg);
                    }
                });

    Friday, April 12, 2019 7:54 PM
  • I highlighted the duplicated call not sure what you are trying to do based on your latest code as you removed far more code than I suggested.  You will obviously need individual handlers.  See https://www.bing.com/api/maps/sdk/mapcontrol/isdk/pushpinallevents
    Friday, April 12, 2019 10:25 PM
    Owner
  • What should be removed from by top thread? I am not following you....
    Friday, April 12, 2019 10:30 PM
  • I am not seeing any highlight. Could you elaborate or point me to some code that does this. 

    Thank you. 

    Tuesday, April 16, 2019 2:52 PM
  • Do you not see bolded text in the response above? Not sure why you would load twice but you will need two handlers.
    Monday, April 22, 2019 4:03 PM
    Owner
  • I have tried every different code combo I can think of and can't get this to work.  Am I attempting something that is not possible? If you totally understand it to put 2 search boxes and 2 autofill forms in this app should be a breeze... Location #1 and Location # 2 ….bam..... https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Autosuggest/Fill%20Address%20Form%20with%20Autosuggest.html
    Tuesday, April 23, 2019 1:47 PM
  • What about trying something like:

    Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', function () {
        var options = {
            maxResults: 4,
            map: map
        };
        var manager = new Microsoft.Maps.AutosuggestManager
    (options);
        var manager2 = new Microsoft.Maps.AutosuggestManager
    (options);
    
        manager.attachAutosuggest('#searchBox', '#searchBoxContainer', selectedSuggestion);
        manager2.attachAutosuggest('#searchBox2', '#searchBoxContainer2', selectedSuggestion2);
    
    });


    Tuesday, April 23, 2019 10:14 PM
    Owner
  • Did you run your above code? I could not get that to work...
    Tuesday, April 23, 2019 11:29 PM
  • you there?
    Wednesday, May 1, 2019 6:56 PM
  • Yes.  You should only need to load the module once then use many.  If that is failing for you I am not sure what is unique in your setup.
    Thursday, May 2, 2019 10:40 PM
    Owner
  • I will go back to your above code and see if I can get that working. Thank you for your patience. 
    Friday, May 3, 2019 12:43 PM