bassjobsen / Bootstrap-3-Typeahead

The Typeahead plugin from Twitter's Bootstrap 2 ready to use with Bootstrap 3 and Bootstrap 4
1.68k stars 1.33k forks source link

Typeahead error: Uncaught TypeError: Cannot read property 'name' of undefined #124

Open PistolPete13 opened 9 years ago

PistolPete13 commented 9 years ago

Admittedly I am just messing this up somewhere, but when I use:

<script type="application/javascript" >
$(document).ready(function(){
    var tags = JSON.parse('["test","testtest","test","asdfasdfasdf","Test","not","a","tag","at","all","awesome","never","Sizes","New Options","New Option Set","test","NameIsBoobos","thenameliterallyisgone","notTagsEleent","NotWorking"]');
    console.log(tags);
    $('#tags').tagsinput({
        typeahead: {
            source: tags
        }
    });
});

On:

<input id="tags" type="text" name="Product[tags]" value="<?php echo implode(",", json_decode($tags)); ?>" class="form-control">

I get the error:

Uncaught TypeError: Cannot read property 'name' of undefinedTypeahead.displayText @ bootstrap3-typeahead.js:248Typeahead.select @ bootstrap3-typeahead.js:83Typeahead.click @ bootstrap3-typeahead.js:397Z.extend.proxy.Z.isFunction.i @ jquery.js:1Z.event.dispatch @ jquery.js:2Z.event.add.m.handle @ jquery.js:2

While it shows the typeahead dropdown perfectly, it doesn't add it to my input value on click, but does add it to the tagsinput field (So I can see it, but the value isn't updating).

PS: The json parse I use cause I echo the data from an PHP array, I saw it on a stackoverflow post...

myehrajat commented 6 years ago

how it can be correct can you find any answer اجاره خودروhttps://ejarehkhodro.com کرایه ماشین در تهرانhttps://021rent.com

skybondsor commented 4 years ago

@PistolPete13 Did you ever figure out the solution here? I'm having the same issue.

skybondsor commented 4 years ago

I figured out that the data I was using for source had a value null in it – and Typeahead definitely doesn't like that! My array looked like:

["Carrie","Michael",null]