sergeyt / meteor-typeahead

Autocomplete package for meteor powered by twitter typeahead.js
https://atmospherejs.com/sergeyt/typeahead
MIT License
146 stars 82 forks source link

Typeahead initialized but no results are returned #111

Closed jasenkoh closed 9 years ago

jasenkoh commented 9 years ago

Hi,

I am able to initialize typeahead and I am able to read input value in helper but tt-dataset is constantly empty.

Am I missing anything?

<template name="navSearch">
  <div class="row">
    <div class="col-xs-12">
      <div class="input-group input-group-lg inner-addon" style="width:100%">
        <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"/>
      </div>
      <!-- /input-group -->
    </div>
    <!-- /.col-xs-12 -->
  </div>
  <!-- /.row -->
</template>
<template name="repo">
       <p class="repo-name">{{name}}</p>
</template>
Template.navSearch.onRendered ->
  Meteor.typeahead.inject()
Template.navSearch.helpers
  repos: (q) ->
    console.log q
    return [
      {name: 'foo'}
      {name: 'bar'}
    ]
sergeyt commented 9 years ago

@jasenkoh try to use data-value-key="name" or return objects with value property which is used by default

jasenkoh commented 9 years ago

@sergeyt you were right, I was missing value property, but also I had to remove q property from repos helper. Although I've tried with array of values (standard example) and it didn't work, again while q was present, once I removed q I was able to see results. When query property is present in helper function does it mean that it expects data to be returned as part of callback function instead of return?

sergeyt commented 9 years ago

@jasenkoh helper function could be of two forms:

  1. without arguments expecting array of suggestions
  2. with 3 arguments (query, sync, async) for custom/async search of suggestions

Also please see the docs for more information.