meteor-autocomplete
meteor-autocomplete copied to clipboard
Multiple field search & display 2 fields in textbox of same collection.
Hi,
I am looking for a use-case as below:
I am considering the same data as provided in the sample application.
Template.single.helpers({ settings: function() { return { position: Session.get("position"), limit: 10, rules: [ { // token: '', collection: StandardLegends, field: 'legend', matchAll: true, template: Template.standardLegends } ] }; }, legends: function() { return StandardLegends.find(); } });
In this case, it searches for a field 'legend' in the collection and displays the same in textbox in UI.
But I am looking for multiple fields search like 'legend', 'code', 'year' ... which mean ... even if I search with any of these values ... my search should succeed.
Along with this, it should also support displaying 2 fields in the textbox in UI like 'legend' & 'year'.
In my case, i would like to search on a users collection ... where user can search on any field like 'firstname', 'lastname', 'email' etc ... And since firstname and lastname are two different fields ... i would like display both in the textbox of UI.
Can you please help me providing the sample on your example .. so that i can follow the same on users collection ?
Advance Thanks.
And another point to mention ..... I am not looking for any tokens here. It can be single/multiple rules ... that's not a problem.
I dont know if this helps but i did the following to search in two fields (frist name and last name)
return {
position: "bottom",
limit: 10,
rules: [{
token: '',
collection: Meteor.users,
field: "_id",
template: Template.userPill,
selector: function(match){
var terms = _.map(match.split(' '), function(key) {return new RegExp("^"+key, 'i'); });
return {'$or': [{'profile.firstName': {'$in': terms}}, {'profile.lastName': {'$in': terms}}]};
}
}]
};
<template name="userPill">
<span class="">{{profile.firstName}} {{profile.lastName}}</span>
</template>
"autocompleteselect #userInfo": function(event, template, doc) {
event.target.value = doc.profile.firstName + ' ' + doc.profile.lastName;
}
Thanks for your time "Juan Camilo Ceron". I will try your suggestions and will update you.
Have a Great Day.
@HemanthAnakapalle Here is my solution of the problem.