Giter Club home page Giter Club logo

Comments (9)

sergeyt avatar sergeyt commented on June 29, 2024

@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.

mrn3 avatar mrn3 commented on June 29, 2024

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.

scottmackenzzz avatar scottmackenzzz commented on June 29, 2024

@mrn3 Thanks for sharing the final solution. Helped me heaps.

from meteor-typeahead.

sergeyt avatar sergeyt commented on June 29, 2024

@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.

mrn3 avatar mrn3 commented on June 29, 2024

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.

sergeyt avatar sergeyt commented on June 29, 2024

@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.

mrn3 avatar mrn3 commented on June 29, 2024

Okay that helps. I guess I am just wondering:

  1. What attribute I should use
  2. What is the syntax to set it
  3. What is the syntax to get it when storing it to the database (I am used to using $("#field").val())

from meteor-typeahead.

sergeyt avatar sergeyt commented on June 29, 2024

@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.

mrn3 avatar mrn3 commented on June 29, 2024

Yeah, I think we can close it - thanks so much!

from meteor-typeahead.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.