I recently started working with Javascript and Meteor and I'm facing some issues with the Meteor autocomplete package from Mizzau. While I am able to get the form auto complete feature to work, I'm struggling to filter my todos accordingly. My main goal is to input a todo in the autocomplete field and have it filter the subscription, or at least provide a search functionality. Currently, the initial state shows 0 todos (none are displayed) and I feel like I might be close to solving this. A significant portion of my code was inspired by this: Meteor - autocomplete with "distinct" feature? Do you think it has something to do with my subscription?
This is my server-side publish call:
Meteor.publish("todosAuto", function(selector, options) {
Autocomplete.publishCursor(Todos.find(selector, options), this);
this.ready();
});
For the client side, my subscription looks like this:
Meteor.subscribe('todosAuto');
The relevant part of my template is as follows:
<div class="container todoFormSec">
<div class="col-md-4">
{{> inputAutocomplete settings=settings id="msg" class="form-control" placeholder="Search..."}}
</div>
<div class="row">
<div class="col-md-5 pull-right">
<h1 class="todocountstyle text-right">You Have {{ todoCount }} Todos</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="todos">
{{ #each todosAuto }}
{{ >todo }}
{{ /each }}
</div>
</div>
</div>
</div>
Here are my settings:
Template.home.helpers({
todos: function() {
return Todos.find();
},
todoCount: function() {
return Todos.find({userid: Meteor.userId()}).count();
},
settings: function() {
return {
position: "top",
limit: 5,
rules: [
{
token: '@',
collection: 'Todos',
field: "title",
subscription: 'todosAuto',
template: Template.titlePill
},
{
token: '#',
collection: 'Todos',
field: "categories",
options: '',
subscription: 'todosAuto',
matchAll: true,
template: Template.dataPiece
}
]
};
}
});
Template.home.events({ // listen for selection and subscribe
"autocompleteselect input": function(event, template, doc) {
Meteor.subscribe("todosAuto", doc.title);
}
});