Honatas / bootstrap-4-autocomplete

A simple autocomplete/typeahead for Bootstrap 4 and jQuery
MIT License
56 stars 31 forks source link

source from database in json format #11

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

I'm struggling with the source option of your autocomplete, I hope you can help me solve the problem When I provide the source from the example

{ "Bootstrap 4 Autocomplete example": 1, "Best example in the world": 2, "Bootstrap 4 Autocomplete is very nice": 3, "It contains neatly arranged example items": 4, "With many autocomplete values": 5, "And it uses default Bootstrap 4 components": 6, "You can use this example to test": 7, }

the autocomplete works.

However, when the source is a url $(function() {$("#table_name").autocomplete({source: "{{=URL('jsonsource', 'name_autocomplete')}}"});}); returning options in the following format:

0: "Bootstrap 4 Autocomplete example" 1: "Best example in the world" 2: "Bootstrap 4 Autocomplete is very nice"

the autocomplete no longer work. I guess I have to set the label and value options, but I have not been able to figure out how.

Thanks in advance for your help.

Annet

Honatas commented 4 years ago

You have to provide a valid object, not an url. Autocomplete will not make any requests, you have to do it yourself, capture the result, transform as needed and only then feed it to the component.