How to use typeahead in multiple fields at the same time?

1

Hello, I wanted to know how I can be using typeahead on various inputs.

I am using Bootstrap and with it I made a row with some inputs, in the first input I am using typeahead to search words, it is possible to clone this row thus making new entries.

The problem is, typeahead only works on the first input, otherwise it does not work.

<input type="text" name="palavras" class="form-control typeahead" data-provide="typeahead">

var substringMatcher = function (strs) {
   return function findMatches(q, cb) {
      var matches, substrRegex;
      matches = [];
      substrRegex = new RegExp(q, 'i');
      $.each(strs, function (i, str) {
         if (substrRegex.test(str)) {
            matches.push(str);
         }
      });
      cb(matches);
   };
};

var palavras= ['olá', 'tudo bem', 'sol', 'praia','neve'];

$('.typeahead').typeahead({
   hint: true,
   highlight: true,
   minLength: 1
},{
  name: 'palavras',
  source: substringMatcher(palavras)
});

I hope to open a legal discussion on this topic.

    
asked by anonymous 13.12.2015 / 15:07

0 answers