GithubHelp home page GithubHelp logo

sergeyt / meteor-typeahead Goto Github PK

View Code? Open in Web Editor NEW
148.0 8.0 82.0 300 KB

Autocomplete package for meteor powered by twitter typeahead.js

Home Page: https://atmospherejs.com/sergeyt/typeahead

License: MIT License

CoffeeScript 0.96% JavaScript 99.04%

meteor-typeahead's Introduction

meteor-typeahead Build Status LICENSE meteor package version

Deps Status DevDeps Status

Twitter's typeahead.js autocomplete package, wrapped for Meteor 1.0+. Issue command meteor add sergeyt:typeahead to install the package.

Initializing typeahead

When the DOM is loaded through Meteor.startup on each template

Meteor.startup(function() {
  Meteor.typeahead.inject();
});

with iron:router

Using iron:router the Meteor.startup is already triggered because it loads the template or the loading template and then inject the data. It must be delayed to when iron:router knows it is rendered completely.

Template.demo.rendered = function() {
  Meteor.typeahead.inject();
};

Examples

See demo application in this repository to find more examples.

data-source attribute

<input class="form-control typeahead" name="team" type="text"
       placeholder="NBA teams"
       autocomplete="off" spellcheck="off"
       data-source="nba"/>
Nba = new Meteor.Collection("nba");

if (Meteor.isServer){
	Nba.insert({name:'Boston Celtics'});
	// fill Nba collection
}

Template.demo.helpers({
  nba: function() {
    return Nba.find().fetch().map(function(it){ return it.name; });
  }
});

Multiple datasets

<template name="demo">
  <div class="form-group">
    <input class="form-control typeahead" name="team" type="text"
           placeholder="NBA and NHL teams"
           autocomplete="off" spellcheck="off"
           data-sets="teams"/>
  </div>
</template>

<template name="team">
	<h4><i>{{name}}</i></h4>
</template>
Template.demo.helpers({
  teams: function() {
    return [
      {
        name: 'nba-teams',
        valueKey: 'name',
        local: function() { return Nba.find().fetch(); },
        header: '<h3 class="league-name">NBA Teams</h3>',
        template: 'team'
      },
      {
        name: 'nhl-teams',
        valueKey: 'name',
        local: function() { return Nhl.find().fetch(); },
        header: '<h3 class="league-name">NHL Teams</h3>',
        template: 'team'
      }
    ];
  }
});

Custom template to render suggestion

<input class="form-control typeahead" name="repo" type="text"
       placeholder="open source projects by Twitter"
       autocomplete="off" spellcheck="off"
       data-source="repos" data-template="repo"/>

<template name="repo">
       <p class="repo-language">{{language}}</p>
       <p class="repo-name">{{name}}</p>
       <p class="repo-description">{{description}}</p>
</template>
Repos = new Meteor.Collection("repos");

if (Meteor.isServer){
	Meteor.startup(function(){
		Repos.remove({});
		// fill repos from private repos.json asset
		JSON.parse(Assets.getText('repos.json')).forEach(function(it){
			Repos.insert(it);
		});
	});
}

if (Meteor.isClient){
  Template.demo.helpers({
    repos: function() {
      // this only works if returned objects have
      // an attribute named "value" containing the text
      // See docs for "data-value-key" attribute
      return Repos.find().fetch();
    }
  });
}

Server side search

<input class="form-control typeahead" name="search" type="text" placeholder="Type to query"
       autocomplete="off" spellcheck="off"
       data-source="search"/>
BigCollection = new Meteor.Collection('bigcollection');

if (Meteor.isServer) {
	Meteor.startup(function() {
		if (!BigCollection.find().count()) {
			// fill BigCollection
		}
	});

	Meteor.methods({
		search: function(query, options) {
			options = options || {};

			// guard against client-side DOS: hard limit to 50
			if (options.limit) {
				options.limit = Math.min(50, Math.abs(options.limit));
			} else {
				options.limit = 50;
			}

			// TODO fix regexp to support multiple tokens
			var regex = new RegExp("^" + query);
			return BigCollection.find({name: {$regex:  regex}}, options).fetch();
		}
	});
} else {

  Template.demo.helpers({
    search = function(query, sync, callback) {
      Meteor.call('search', query, {}, function(err, res) {
        if (err) {
          console.log(err);
          return;
        }
        callback(res.map(function(v){ return {value: v.name}; }));
      });
    }
  });
}

Catching selected event with id

Template.example.rendered = function() {
  Meteor.typeahead.inject();
}

Template.example.helpers({
  items: function() {
    // data source function
    // TODO fetch items from meteor collection
    return someCollections.find().fetch().map(function(object){ return {id: object._id, value: object.value}; });
  },
  selected: function(event, suggestion, datasetName) {
    // event - the jQuery event object
    // suggestion - the suggestion object
    // datasetName - the name of the dataset the suggestion belongs to
    // TODO your event handler here
    console.log(suggestion.id);
  }
});

Template:

<template name="example">
  <input placeholder="Kies een plaats" autocomplete="off" spellcheck="off"
      data-source="items" data-select="selected"/>
</template>

Styling

By default, there is no style applied with this package. If you want the same styling as in the demo app, please do the following:

  • add bootstrap: meteor add twbs:bootstrap
  • add the style.css file to your application

meteor-typeahead's People

Contributors

assertnotnull avatar ayhid avatar bbln avatar benmgreene avatar chip avatar cinjon avatar dandv avatar davidfurlong avatar doctorpangloss avatar elidoran avatar eluck avatar etodanik avatar flowen avatar grigio avatar janat08 avatar kentshikama avatar kristijanhusak avatar laran avatar manybothans avatar pierreozoux avatar raphox avatar s7dhansh avatar sergeyt avatar siyfion avatar teamoo avatar volodymyr-k avatar vsivsi avatar yarivgilad avatar zhenyasav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-typeahead's Issues

"wrap_value is not defined" error

Using Meteor 0.9.3.1, sergeyt:typeahead 0.10.5_2

Here is my template code:

<template name="journal_form">
  {{# autoForm collection="JournalEntries" id="journal_form" type="insert"}}
    <fieldset>

      <input type="text" name='student' class='form-control typeahead' placeholder='Type student' autocomplete='off' spellcheck='off' data-source='students' />

      {{> afQuickField name='comm_date' options='auto' value=today}}
      {{> afQuickField name='comm_type' options='auto'}}
      {{> afQuickField name='comm_with' options='auto'}}
      {{> afQuickField name='reason' options='auto'}}
      {{> afQuickField name='notes' options='auto' rows=5}}
      {{> afFieldInput name='user_id' type='hidden' value=currentUser.profile.name}}
    </fieldset>
    <button type="submit" class="btn btn-primary">Add Journal</button>
  {{/autoForm}}
</template>

Here is my javascript:

if (Meteor.isClient) {
  Template.journal_form.rendered = function() { 
    Meteor.typeahead.inject();
  };

  Template.journal_form.students = function() {
      console.log('loading students');
      return ['Mike','Mark','Janet','Jeff','Jeffrey'];
  };
}

It's throwing the following exception:

ReferenceError: wrap_value is not defined
    at make_bloodhound (http://localhost:3000/packages/sergeyt_typeahead.js?5f7b454b1a08a406363bfb96b16e81ad8f2683ef:2107:38)
    at resolve_datasets (http://localhost:3000/packages/sergeyt_typeahead.js?5f7b454b1a08a406363bfb96b16e81ad8f2683ef:1983:10)
    at Object.Meteor.typeahead (http://localhost:3000/packages/sergeyt_typeahead.js?5f7b454b1a08a406363bfb96b16e81ad8f2683ef:1853:17)
    at null.<anonymous> (http://localhost:3000/packages/sergeyt_typeahead.js?5f7b454b1a08a406363bfb96b16e81ad8f2683ef:1913:11)
    at Function.jQuery.extend.each (http://localhost:3000/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:417:23)
    at jQuery.fn.jQuery.each (http://localhost:3000/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:170:17)
    at Function.Meteor.typeahead.inject (http://localhost:3000/packages/sergeyt_typeahead.js?5f7b454b1a08a406363bfb96b16e81ad8f2683ef:1911:14)
    at Template.journal_form.rendered (http://localhost:3000/utilitybelt.js?07826136f2a6db6b0d828233fd68be6f7088066e:17:22)
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2924:21)
    at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1720:14

Problem with Multiple-datasets

Hi, I'm trying to use the multiple dataset feature of your plugin but I can't make it work. Apparently the function "resolve_template_function" is throwing an error. The property "view.template" is null for some reason, so the plugin can't find my "data-sets". I don't know if I'm doing something wrong. I used the code below to test:

-- JS

Template.my_template.rendered = function() {
Meteor.typeahead.inject();
};

Template.my_template.alimentos = function() {
return ['arroz', 'feijão', 'macarrão', 'pizza', 'cerveja', 'salmão', 'alcaparras', 'pernil' ];
};

-- HTML

input class="form-control typeahead" name="alimento_refeicao" type="text" placeholder="Ex: arroz" autocomplete="on" spellcheck="off" data-sets="alimentos"

I also tried using exactly the same example of NBA and NFL teams, (returning "name", "local", and "header") but doesn't work neither.

Am I doing something wrong? Thank you.

[email protected] breaks typeahead

I use your package with autoform and simple-schema and a typeahead template. There is a collection and a helper function that provides the values. All worked great

<template name="afInput_cuisine_typeahead">
    {{! https://github.com/aldeed/meteor-autoform/issues/215 }}
    <input type="text" data-schema-key="{{this.name}}" name="{{this.name}}" class="{{this.cls}} form-control typeahead" value="{{this.value}}" autocomplete="off" spellcheck="off" data-source="cuisine" {{this.atts}}/>
</template>

but ever since I upgraded to 0.9.4 I get this error

Exception from Tracker afterFlush function: invalid dataset name: restaurant.cuisine
error@http://example.com/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:281:18
Dataset@http://example.com/packages/sergeyt_typeahead.js?432d72e5901672b2c94d17f5b8bbaefe5c815e7a:1201:24
initializeDataset@http://example.com/packages/sergeyt_typeahead.js?432d72e5901672b2c94d17f5b8bbaefe5c815e7a:1482
...

Now, I do NOT know if it IS this package or autoform that does something weird since 0.9.4 but since it is only the typeahead field I figured I start here.

Basic install code missing / unclear in the Readme file

Sergey hello
Your meteor package looks awesome!
Can you please include a basic install code to add it to a Meteor app?
I tried "meteor add sergeyt:meteor-typeahead" and the package could not be found
npm install workflow in a meteor app is a bit of a blur for newbies like me.
Can you please explain?
Cheers
Ajar

Unable to get custom template to work

Thank you for this amazing package! Saved me a lot of time.

I am able to get the basic example working in my website. However when I tried to implement the custom template example, it doesn't work. The suggestions just don't show up. I have done everything shown in the example. I am using meteor 1.0.3.2

I was also wondering how the text search is done in case of custom template. the find().fetch() returns objects right..so how does it know which property should be used to match the text entered with?

Thanks!

Best,
Vivek

Few issues!

Firstly, great work with this wrapper, it's almost perfect for my use-case, which is always nice! 👍

Okay, so issues:

  • The data-selected value takes a helper function, however inside that helper function Template.instance() no longer returns the template instance associated with the helper, it just returns null. This is really awkward when trying to set anything that exists on the template instance, which is quite a likely use-case!
  • If you have two templates rendered at any one point, both with typeahead controls in them, calling Meteor.typeahead.inject(); in both template's rendered functions causes some serious issues. However, not doing so means that each template cannot be used anywhere else, independently.

Set data attribute on selected input

How can I use typeahead to set also some other data attribute on selected value. I would like to set also the document id in data-id attribute.

Template for No Results

Hey, is there a way to set a template that will appear when the input is first focused and when there are 0 results from all the datasets?

problem with searching multiple collections

when I search a single collection everything works fine but when I want to search over multiple collections I get =>

TypeError {stack: (...), message: "undefined is not a function"}

Its hard to debug because I don't see what im doing wrong in my code.

It has to do with the fact that the data is not immediately available and reruns when the data arrives. This is frustrating because when I use a single data source it works.

Exception from Deps recompute function: whitespace

Hi, I seem to be gettting this erro from using a custom template, it works fine when I dont use a custom template

Using Meteor 0.8.3

FORM CODE

<template name="usernameAutocomplete">
  <form class="mainnav-form pull-right search-users" role="search">
    <input class="form-control typeahead" name="userPill" type="text"
    placeholder="Type a username"
    autocomplete="off" spellcheck="off"
    data-source="searchNav" data-template="userItem"/>
  </form>
</template>
<template name="userItem">
<p>{{username}}</p>
</template>

JS CODE

Template.usernameAutocomplete.searchNav = function(){
    return Meteor.users.find().fetch();
}

FULL ERROR

"Exception from Deps recompute function: whitespace@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:169:13
tokenize@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:177:21
SearchIndex</<.add/<@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:417:21
reverseArgs@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:69:17
.each@http://localhost:3000/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:417:6
_.each@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:67:13
SearchIndex</<.add@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:414:17
add@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:667:17
addLocalToIndex@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:660:21
jQuery.Callbacks/fire@http://localhost:3000/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:3132:1
jQuery.Callbacks/self.add@http://localhost:3000/packages/jquery.js?265926494aaa3929cd2e30da265211c5929f37a4:3178:7
initialize@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:656:17
initialize@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:664:24
make_bloodhound/<@http://localhost:3000/packages/typeahead.js?133bec3ec940e41b4a0ca0e080ab808cf3ff5876:1999:5
Deps.Computation.prototype._compute@http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:214:5
Deps.Computation.prototype._recompute@http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:228:9
Deps.flush@http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:322:9
"

.tt-cursor css missing?

Hi, I tried your demo and it seems some typeahead css are missing.
With the style below the item is selected on the list while you type

.tt-cursor {
background-color:red;
}

Symbolic link issue with Meteorite

meteorite symbolic links to the typeahead package with an absolute path. This means that in Git, packages/typeahead is always marked as changed whenever a developer runs the server. I see this issue with typeahead:

diff --git a/packages/typeahead b/packages/typeahead
index 3e0ec11..b8d27bc 120000
--- a/packages/typeahead
+++ b/packages/typeahead
@@ -1 +1 @@
-/Users/Jay/.meteorite/packages/typeahead/sergeyt/meteor-typeahead/fe0bb03aea8493037de134d815f9663feb21a944
\ No newline at end of file
+/Users/bberman/.meteorite/packages/typeahead/sergeyt/meteor-typeahead/fe0bb03aea8493037de134d815f9663feb21a944
\ No newline at end of file

When Jay runs the app with bberman's commit, he'll see:

=> Your application has errors. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:

While building the application:
error: no such package: 'typeahead'

This may be a meteorite issue but I only see it with your package. You can reproduce it by doing mrt add typeahead on a blank project, committing to git, and then pulling your changes on a computer where the absolute path to typeahead would be different (e.g., a different user account).

Save id instead of text

I would like to save the id of the selected value, rather than just the value. Basically, this is the way you do it in jquery:

http://stackoverflow.com/questions/4815330/jquery-autocomplete-with-item-and-id

I realize there has been some discussion about this, but I am not sure I fully have wrapped my head around it:

#19

Could you provide some sample code or augment mine?

My template:

My member_item.js:

Template[getTemplate('member_item')].helpers({
membersList: function(){
return Members.find().fetch().map(function(member){ return member.FullName; });
}
});

Template[getTemplate('member_item')].rendered = function(){
Meteor.typeahead.inject();
};

Template[getTemplate('member_item')].selected= function(event, suggestion, datasetName) {
// TODO your event handler here
console.log(suggestion);
console.log(datasetName);
}

When I do this, it just outputs the suggestion object as text, but I am trying to figure out how to get the id of the member from this.

minLength 0

Hello,
Is there a way to have the drop down open on focus?
The way select2 works.

Thanks

Typeahead won't work

Is there a way to find out what the problem with my setup is? When I just put my data-source as {{entries}} into my template, it shows the correct entries. However, when I type something I don't get any results.

Deprecation of old helpers syntax

Meteor 0.9.4 released, and the old syntax is deprecated.
Accessing __helpers is possible, but I think a redesign is needed.

function resolve_template_function(element, name) {
    var fn = null;

    if (typeof Blaze == "undefined") {
        var component = UI.DomRange.getContainingComponent(element);
        if (!component) {
            return [];
        }
        fn = component[name];
    } else {
        var view = $.isFunction(Blaze.getView) ? Blaze.getView(element) : Blaze.getElementView(element);
        if (!view) {
            return [];
        }
        fn = view.template && view.template.__helpers.get(name);
    }

    if (!$.isFunction(fn)) {
        console.log("Unable to resolve data source function '%s'.", name);
        return [];
    }

    return fn;
}

Show results as different template and not inside a dropdown

Hi,
Is it possible to show the search results in a separate template without it being part of a dropdown? In my use case, there is a list of the current user's contact list with a search bar on top. By default, the list shows all the contacts but I was to filter it based on the search result. How can I do this?

Getting Meteor-Typeahead to Work

For some reason, I can't get this package to work. I have a very basic setup and must be missing something. Do you mind taking a look and seeing where I'm going wrong? I'm fully updated according to 'mrt update' and I'm getting no console error reports.

In the html page:

<template name="companies">
  <input class="form-control left typeahead" type="text" autocomplete="off" spellcheck="off" data-source="company_typeahead" id="search_company" placeholder="Search Company"/>
</template>

In the JS:

Template.companies.company_typeahead = function() {
  return Companies.find().fetch().map(function(company) {
    return company.name;
  });
}

Template.companies.rendered = function() {
  Meteor.typeahead.inject();
  // Also tried Meteor.typeahead($('.typeahead'))
  // And Meteor.typeahead($('.typeahead'), Companies.find().fetch().map(function(company) {
  // return company.name;
  // }))
}

Meteor.typeahead is not available on client

typeahed was added to meteor.

"typeahead": {
        "git": "https://github.com/sergeyt/meteor-typeahead.git",
        "tag": "v0.0.6",
        "commit": "79b17707e3244f87af08a1a59e1ac4088f3e8644"
}

typeahead fails if form element inside conditional block

Hi there - took me a painful amount of time to track this down but it seems like typeahead fails if it's inside a conditional block. I had part of a template inside {{#if currentUser}} and eventually (after trying everything else under the sun) realized it seems to be any conditional that causes it to fail. I.e. using the basic example, putting this in the template -

{{#if 1}}
<input class="form-control typeahead" name="team" type="text"
       placeholder="NBA teams"
       autocomplete="off" spellcheck="off"
       data-source="nba"/>
{{/if}}

makes it nonfunctional. Sometimes it fails silently, sometimes I get "Unable to resolve data source function 'nba'." and I'm not sure what yet causes that, but hope this is enough to track it down. Thanks.

Use the new versioning convention for wrapper

Meteor 0.9.3 introduced the _ operator that help versioning libraries wrapping for Meteor. The idea is to use the version number of the library, followed by _n with n being incremented for each modification of the wrapper itself.

So this package could use version 0.10.5_1.

Pressing enter will no longer submit form

I'm currently using this with my meteor-editable package in an app. For some reason my app decided to update yesterday from 0.10.5_9 to 0.10.5_12. Didn't think much of it at first but now my tests fail. The form I have it in in has no submit button, it relies on enter being pressed to submit the form this previously worked and no longer does. I did a diff between the two version commit shas and couldn't see anything that stood out as to why this would be happening.

Server side search example

Hi I'm trying your example "Server side search example" on a blank Meteor app.
It seems the data-source="search" is not bind to Template.search.search no events are fired, is something missing?
Thanks

Typeahead not activated?

This might be the same as issue #8.

I've installed typeahead using mrt add typeahead and then attaching the typeahead class to one of my input fields:

<input type="text" class="form-control typeahead" name="clubName" autocomplete="off" spellcheck="off" data-source="clubs"/>

Unfortunately nothing happens when I type in.

If I cd into packages/typeahead/demo and run your demo it works fine. I can put a breakpoint on line 40 of index.js and the breakpoint is reached when I refresh the page.

However, if I run my own app and put a breakpoint in the same place, it's never called.

Any idea why it's not working? What else do I need to do?

Thanks

Not working with Meteor v0.9.1

Breaking from the new Blaze updates. Getting the following exception in Web Inspector:

Exception from Tracker afterFlush function: undefined is not a function
TypeError: undefined is not a function
    at resolve_template_function (http://localhost:3000/packages/sergeyt:typeahead.js?012115c55b6c6f1a318aa003d312b3437be5612d:1907:20)
    at resolve_datasets (http://localhost:3000/packages/sergeyt:typeahead.js?012115c55b6c6f1a318aa003d312b3437be5612d:1848:15)
    at Object.Meteor.typeahead (http://localhost:3000/packages/sergeyt:typeahead.js?012115c55b6c6f1a318aa003d312b3437be5612d:1776:17)
    at Template.searchBar.rendered (http://localhost:3000/client/views/includes/search.js?89a2fabf2f17abeef220aa87d87c9f33257adb80:7:12)
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2807:21)
    at http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1712:14
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:2017:12)
    at http://localhost:3000/packages/blaze.js?5ec4e54b22ab2196bcc772669c0619f71666393e:1711:15
    at Tracker.flush (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:438:11)

Caused by this line:
https://github.com/sergeyt/meteor-typeahead/blob/master/index.js#L168

typeahead-wait-ms not supported?

Wondering if the option for typeahead-wait-ms is supported in the latest version? I have everything working as expected so far, but I am trying to delay my API requests so that when I type a search term, I'm not firing an API call for every single letter that is typed. I think that defining typeahead-wait-ms is the correct solution, but it doesn't appear that it has any effect when defined in the input like this:

Async data-source with multiple datasets

I tried returning multiple datasets via the callback (using the email async example) with no luck. For each dataset 'undefined' would be rendered to the dropdown list. Is there any way to have more than one dataset when dealing with async data?

Custom template with multiple datasets

Hi :)
I am trying to setup a custom template for multiple datasets.

  <input class="form-control typeahead" name="team" type="text" placeholder="Search"           autocomplete="off" spellcheck="off" data-sets="results" data-template="customTpl"/>

<template name="customTpl">
  <h4><a href="/{{name}}">{{name}}</a></h4>
</template>
Template.searchNavBar.results = function(){
    return [
            {
                name: 'Books',
                local: function(){ return Books.find().fetch().map(function(it){ return it.name; });},
                header: '<h3 class="league-name">Books</h3>',
            },
            {
                name: 'Authors',
                local: function(){ return Authors.find().fetch().map(function(it){ return it.name; });},
                header: '<h3 class="league-name">Authors</h3>'
            },
        ];

}

it looks great but it does not take into account my custom template.

Also... looks like the .css file to style typeahead was not installed properly.

Thanks

search starts on page load, not on keyup

It seems like the way the demos are set up, it starts searching the collection immediately with no parameters, i.e. .find() everything. I didn't notice this until I dropped some logging into the search function. I'm looking into how to trigger this off keyup instead and will post if/when I figure it out, but thought I'd ask in case I'm missing something. Thanks!

Can't select typeahead on mobile

Hello,

I have had success using your package for the web. The package also works on mobile safari, which is great. However, when I try using it with iOS through phonegap, the typeahead suggestion is not selectable. When I press the typeahead selection, rather than autocompleting the remainder of the phrase, the suggestion dropdown disappears, and the text is left wherever you stopped typing.

This is tested with: sergeyt:[email protected]_7, Meteor 1.0, iOS 8.0 (both iOS simulator and on physical device)

To test this out, try running the following on the demo app provided with this project (assumes you have XCode and iOS Simulator installed):

meteor add-platform ios
meteor run ios

In the first NBA teams textbox enter Char
Charlotte Bobcats witll appear as a suggestion
Click on the suggestion

Expected response: textbox autocompletes with Charlotte Bobcats
Actual response: textbox remains at Char and the suggestion dropdown disappears

return object from collection

Hi.

Can I return an object rather than a string from a collection? I'd like to add name and _id to a new collection from the typeahead-input, like:.

return Participants.find().fetch().map(function (post) { return post; });

And in html use something like:

In angularjs one can use ngModel=user.name to display the name and use other fields as needed.

regards
Claus

How should I clear an open list of suggestions?

I've got a search input. Once you start typing and suggestions appear, if you continue typing out a matching suggestion (without actually selecting it) the suggestion list / drop-down doesn't go away. I'd like to be able to manually clear it in this case but I'm not seeing how. Thanks!

data-hint – If false, the typeahead will not show a hint. Defaults to true.

Thanks for your great meteor typeahead package : ]

I was trying to config the typeahead to show the autocomplete hint, so it will autocomplete the query if a user press tab, but it was not shown in the demo (http://typeahead.meteor.com/) as well.

After looking deeper, seems like it works if I specify data attr 'data-hint' to be 'true'.

According to your documentation(https://github.com/sergeyt/meteor-typeahead/blob/master/docs.md) for typeahead options data-hint – If false, the typeahead will not show a hint. Defaults to true.

Seems like the defaults is false for some reason
index.js (https://github.com/sergeyt/meteor-typeahead/blob/master/index.js)
var hint = Boolean($e.data('hint')) || false;

Cheers!
Winston

Get the suggesstion onclick

Hello,

Is there a way when you click on a suggestion the the page will redirect. The jquery code will be:

jQuery('#autocomplete-input').on('typeahead:selected', function (e, Item) {
window.location = "#item/ID="+Item;
});

My meteor code is:

Template.plaatsinputleft.rendered = function() {
Meteor.typeahead.inject();
}

Template is:


Thank you..

Support prefetch option

If data-source contains '/' char than it would be considered as url for prefetched data, see prefetch example here.

Remove style.css

  • 2px border-radius as in bootstrap input
  • replace .tt-query with .tt-input

Outdated documentation for multiple datasets examples

Sorry, I couldn't find a more suitable place to ask for help.
How do results get rendered?

screen shot 2015-04-02 at 11 48 28 pm

In the above examples, 3 out of 80 courses there are three courses that have "matlab" in their titles. The number of results seems to be correct when I search for the string, but how come each result returns undefined instead of the string?

Also, what is displayKey or valueKey?
Maybe the document for examples is outdated?

Maybe it's related to this issue: twitter/typeahead.js#927

EDIT: The problem was that the actual code and code gist in the document were different.
I will file a PR later

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.