Hansje
Hansje

Reputation: 21

Simple typeahead.js code works only on old typeahead release 0.9.3 not in later ones

I am learning typeahead from the book. When I use the 0.9.3 typeahead release, the typeahead works fine. When I use a lter release from typeahead like 0.11.1 or 0.10.0 it does not work anymore.

So what should I change in my code so that it will work also in newer typeahead releases? (I am using the latest jquery version)

<html>
<head><script type="text/javascript" src="components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="components/typeahead.js/dist/typeahead.jquery.min.0.9.3.js"></script>
<title>Friend Finder</title>
</head>
<body>
     <label for="friends">Pick Your Friend</label>
        <input type="text" name="dummy" class="typeahead"/>
        <script>
        $(document).ready(function() {
        $('input').typeahead({  
            minLength: 1,       
          name: 'people',
          local: ['Elaine', 'Column', 'Kirsty', 'Chris Elder']
        });
        });
        </script>
</body>
</html>

p.s. learning from the book: Instant typeahead.js from Toby Osbourn

Upvotes: 1

Views: 383

Answers (1)

Hansje
Hansje

Reputation: 21

I found the explanation on Github since from 0.9.x to 0.10.0 things changed: From Typeahead version 0.10.0 things have changed. That is the reason why this simple code does not work anymore in newer versions. With version 0.9.3 it will work. Read on this link the Notable Changes!:: Migrating to typeahead.js v0.10.0

  1. typeahead function needs now a first argument, then the dataset
  2. the way datasets are used are changed since Bloodhoud has been introduced from version 0.10.0

....copy pastef from github: ...>> As you can see, local, prefetch, and remote are no longer defined at the dataset level. Instead, all you set in a dataset config is source. source is expected to be a function with the signature function(query, callback). When a typeahead's query changes, suggestions will be requested from source. It's expected source will compute the suggestion set and invoke callback with an array of suggestion objects. The typeahead will then go on to render those suggestions.

Upvotes: 1

Related Questions