twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Suggestions not showing inside Table Row #1804

Open utsavDave97 opened 2 years ago

utsavDave97 commented 2 years ago

Describe the bug Suggestions not showing inside Table Row

As you can see in the below screenshot whenever I click on Add Dependents it would dynamically add a table row as shown in the screenshot. Inside the screenshot you can also see that when I type A the console does output 4 suggestions but it is not being displayed or rendered in the browser. Screen Shot 2022-05-05 at 8 23 58 PM

Moreover when the user taps Add Dependents this is the code which gets called.

var i = 0;
$("#add-dependent-button").click(function (e) {
    document.getElementById("dependentTable").style.display="block";
    ++i;
    $("#dynamicAddRemove").append('<tr><td><input class="typeahead2 form-control" type="text" name="dependents[' + i +
        '][client_id]" placeholder="Start typing name..." required"/></td><td><select class="form-control" id="relationship" name="dependents['+i+'][relationship]">@foreach($relationships as $relationship)<option value="{{$relationship->id}}">{{$relationship->relation}}</option>@endforeach</select></td><td><button type="button" class="btn btn-outline-danger remove-input-field">Remove</button></td></tr>'
    );
    $('input.typeahead2').typeahead({
        source:  function (query, process) {
            console.log(`${query}`);
            return $.get(path, { query: query }, function (data) {
                console.log(`${data}`);
                return process(data);
            });
        }
    });
    e.preventDefault();
});

I am using bootstrap and Laravel.

Appreciate your help!