Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an input: event for the input field prevents autoComplete from starting the query #336

Open
8 tasks
john-999 opened this issue Apr 12, 2022 · 2 comments
Labels
question Further information is requested

Comments

@john-999
Copy link

  • System Information

    • Browser type and version: Firefox 99.0
    • OS type and version: Linux: Ubuntu 20.04.4 LTS
    • Node version (IF applicable): None
    • Any error messages in the JS console: None
  • Describe the bug

If I add an input event for the input field (= an event that is fired when the field value is changed, both on desktop and mobile), then autoComplete won't launch the query, and therefor show no result list.

Is this a bug or a feature (= happening because the inbuilt input event is then overridden)?

If this is a feature: What would I need to add to the example code extract below to have autoComplete start the query correctly?

  • To Reproduce
new autoComplete({
  events: {
    input: {
      input: (event) => {     
        console.log(event);
      }
    }
  }
});
  • Expected behavior
    The input event is correctly recognized by autoComplete, but the query should also be started, then displaying the result list.
@john-999 john-999 added the bug Something isn't working label Apr 12, 2022
@TarekRaafat
Copy link
Owner

Hello @john-999,

All you need to do to fix that behavior is to use the autoCompleteJS.start(query); API inside the input event as shown below.

events: {
  input: {
    input(event) {
      autoCompleteJS.start();
      console.log(event);
    },
  }
}

Please try it and let me know how it goes.

Cheers! :)

@john-999
Copy link
Author

john-999 commented Apr 12, 2022

Thanks!

But as I understand it, this would then not apply the "debounce" value, right? Is there a way to make debounce happen as well? Because the below attempt wouldn't work like the "debounce" feature...

events: {
  input: {
    input(event) {
      setTimeout(function() {
        autoCompleteJS.start();
      }, repeat_debounce_value_here);

      console.log(event);
    },
  }
}

So there seems to be a certain contradiction:

autoCompleteJS.start(); takes into account the threshold: value, but not the debounce: value.

So, would it then make sense to make autoCompleteJS.start(); respect the debounce: value as well?

@TarekRaafat TarekRaafat added question Further information is requested and removed bug Something isn't working labels Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants