Comments (9)
@mrn3 try to return in memberList
array of objects with id
and value
properties (BTW value
is default property used by typeahead suggestion engine), in selected
event you should get the suggestion object instead of string.
from meteor-typeahead.
Okay, perfect - that is working for me now:
Template[getTemplate('member_item')].helpers({
membersList: function(){
return Members.find().fetch().map(function(member){ return { id: member._id, value: member.FullName }});
}
});
So now I have the event firing and it dumps the write id to the console when it is selected:
Object {id: "FA9dj4RLBG3juYcPp", value: "Newman, Matt"}
So do you suggest that I just have a hidden field that is populated when that is selected? I assume that is how to do it, right? I can't just change an attribute on the original select input can I? I think on #19 they mentioned populating a data-item attribute, right? How do you reference that later? I am used to something like $('#FullName').val().
Thanks again!
from meteor-typeahead.
@mrn3 Thanks for sharing the final solution. Helped me heaps.
from meteor-typeahead.
@mrn3 could you please clarify your use case? do you want to bind selected item id to typeahead input value/attibute? why don't use meteor bindings, i.e. use observable field to store current value to bind it to input value/attribute, in selected
event handler just change the value of the field.
from meteor-typeahead.
Yeah, I basically just want to store the ids in the database, rather than the text values that the user selects (similar to what a typical select input does). I can do this if I create another input field for each typeahead input I create, but ideally, I would just update some attribute of the typeahead input field so I don't have to have two inputs for every field I want (one visible one, and one hidden one). Is there a way to accomplish this?
from meteor-typeahead.
@mrn3 you could bind selected id
to some attribute of the same typeahead input (no need hidden input), and store selected id
in the database in selected
event handler.
from meteor-typeahead.
Okay that helps. I guess I am just wondering:
- What attribute I should use
- What is the syntax to set it
- What is the syntax to get it when storing it to the database (I am used to using $("#field").val())
from meteor-typeahead.
@mrn3 I think this topic is exhausted since you see the solution now, is not it? Also I think that the following feature could be implemented in this package. data-source
attribute accepts meteor collections, e.g collection:Members.FullName
value specifies that auto-complete suggestions will be fetched from Members
collection and FullName
property will be used as label, suggestion object has id
and value
properties. This could reduce app code a bit (i.e. no need to write memberList
template helper), but anyway selected id
should be handled in selected
event handler to store the value in other meteor collection, session, local storage, etc.
from meteor-typeahead.
Yeah, I think we can close it - thanks so much!
from meteor-typeahead.
Related Issues (20)
- notFound Template HOT 2
- Typeahead with FlowRouter HOT 7
- Could I use with "AutoForm"? HOT 2
- compatibility with twbs 4 HOT 1
- compatibility with meteorhacks:kadira-debug HOT 1
- can i search anything b/w a words HOT 1
- Not working on Meteor 1.2.1 HOT 5
- Unique assign data-source values.
- data-autoselect doesn't work HOT 3
- Searching whole words
- data-min-length setting bug HOT 1
- Server side search doesn't work in demo
- data-source parameter HOT 1
- Custom Templates not working... HOT 3
- Typeahead always shows only 5 suggestions maximum HOT 2
- How to search username with image?
- meteor 1.6.1 compatibility? HOT 5
- Updating typeahead from maintained forks HOT 5
- Can't bind and operate on typeahead element HOT 1
- Look for 2 or more fields
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-typeahead.