xcash / bootstrap-autocomplete

Bootstrap Autocomplete
MIT License
168 stars 72 forks source link

Selecting a result sets the field's value without firing `input` event #84

Closed reeseovine closed 4 years ago

reeseovine commented 4 years ago

Describe the bug Events that are typically emitted by entering text into a field are not fired when a suggestion is selected from the list.

Steps to reproduce the behavior

  1. Initialize autocomplete

    $('#field').autoComplete({
    resolverSettings: {
    url: 'testdata/test-list.json'
    }
    })
  2. Bind a handler to the input event.

    $('#field').on('input', function(){
    console.log(this.value);
    })
  3. Start typing, and watch text being added to the log.

  4. Select a suggestion with the keyboard or mouse.

  5. Notice that selecting the suggestion did not fire the event to log to the console.

Expected behavior I would expect selecting a suggestion to fire the relevant event(s) as if the user typed it, unless there is a different event I should be binding to that I am unaware of.

Desktop

Additional context My use case does not involve any server-side processing. Instead the data is processed in the browser in real-time as the user types.

reeseovine commented 4 years ago

I figured it out by looking through the code. It's as simple as

$('#field').on('input autocomplete.select', function(){
  console.log(this.value);
})

to bind the function to both events.