Meteor-Community-Packages / meteor-autocomplete

Client/server autocompletion designed for Meteor's collections and reactivity.
https://atmospherejs.com/mizzao/autocomplete
MIT License
350 stars 107 forks source link

How to clear input box after user selects value #104

Closed amnevins closed 9 years ago

amnevins commented 9 years ago

I am using your package and love it. Users can select their favorite brands, and upon selection I add them to the users favorites. However, the box remains filled with the brand name they just selected and they have to delete the name to add another. Is there an easy way to immediately set the boxes value back to blank after they select it from the drop down? I appreciate the help, thanks for the awesome work!

Template.favorites.events({ "autocompleteselect input": function(event, template, doc) { //console.log("selected ", doc);

    var brandAlliance = {

        Name: doc.Name,
        Id: doc.Id,
        IconImageUrl: doc.IconImageUrl,
        LandingPageUrl: doc.LandingPageUrl

    };
    //console.log(brandAlliance);

    Meteor.call("brandAddAlliance", brandAlliance);

});

Assios commented 9 years ago

Just add an ID to the input field, e.g. like this:

{> inputAutocomplete settings=settings class="form-control" id="auto-input"}}

and then call

document.getElementById('auto-input').value = '';

whenever you want to clear the input box.

amnevins commented 9 years ago

Thanks for answering !