SDFIdk / dawa-autocomplete2

DAWA Autocomplete2 is a JavaScript-component which makes it possible to enter a danish address in a single input field.
MIT License
14 stars 4 forks source link

When selecting an autocomplete suggestion with the mouse, component.selected is not (always) set #16

Open woutervanvliet opened 3 weeks ago

woutervanvliet commented 3 weeks ago

Steps to reproduce:

  1. Enter a partial address that results in multiple autocomplete suggestions in the address field (for example: Provstejorden 3)
  2. Use the mouse to select any of the options (for example: Provstejorden 30, 9000 Aalborg)
  3. Observe that the "select" callback is called
  4. Observe that "component.selected()" keeps it's original value
  5. Clicking in the field again, then selecting the only suggested option will update the components internal selected state

The following modification to the first autocomplete control on the demo page makes it clear to see:

 const component = dawaAutocomplete.dawaAutocomplete(document.getElementById("adresse"), {
    select: function(selected) {
    document.getElementById("valgtadresse").innerHTML= selected.tekst;
      console.log('Selected address: -- ', this);
      console.dir(selected);
      console.log('selected', component.selected())
    }
  });