konsalex / Airport-Autocomplete-JS

Airport Autocomplete Input tag
MIT License
31 stars 18 forks source link

Can't choose airport from the list #3

Closed mixerowsky closed 5 years ago

mixerowsky commented 5 years ago

Hi @konsalex !

I found the issue in the latest version.

When you search for the airport you get suggestions but can't select nothing from the list to fill in the field.

It could be good idea that it's possible to choose what you want as field value after you select some airport from the suggestion list as well.

konsalex commented 5 years ago

Hey @mixerowsky .

Did you add the data-index="$(i)" in the parent div of the result?

If not the onClick controller can't know which result you clicked! It is required, I updated the README.md 😅

mixerowsky commented 5 years ago

Yes, I did, and I see index in markup.

Here is my options:

        const airportOptions = {
          shouldSort: true,
          threshold: 0.4,
          maxPatternLength: 32,
          includeMatches: true,
          minMatchCharLength: 3,
          formatting: `<div class="$(unique-result) single-result" data-index="$(i)"><div class="airport-data">$(name)<br>$(city) ,$(country)</div><div class="airport-code">$(IATA)</div></div>`
        };
konsalex commented 5 years ago

Hey @mixerowsky there are four issues here.

A working example is the following :

 const airportOptions = {
           fuse_options : { 
               shouldSort: true,
              threshold: 0.4,
              maxPatternLength: 32,
              minMatchCharLength: 3,
              keys: [{
                 name: "IATA",
                weight: 0.6
                 },
                {
                   name: "name",
                   weight: 0.4
                },
              {
                 name: "city",
                weight: 0.2
              }
          ]
         },
          formatting: `<div class="$(unique-result) single-result" data-index=$(i)><div class="airport-data" data-index=$(i)>$(name)<br>$(city) ,$(country)</div><div class="airport-code" data-index=$(i)>$(IATA)</div></div>`
        };

I publish a quick change to the code and again with the latest you should see the changes. I will close this issue and if you find any additional error feel free to re-open it.