Topic: Autocomplete with dynamic values loading

David Macek pro asked 5 years ago


Hi guys, not a question, just a possible info. As I couldn't find a solution to autoload data to the "Autocomplete" field, I created the following snippet which might be useful. Cheers, David

https://mdbootstrap.com/snippets/jquery/david_macek/378830


David Macek pro answered 5 years ago


Well, the snippet works well but the problem is that if the autocomplete values are loaded dynamically (and asynchronously), I would need a way to force the system to display the values when they are loaded. Instead, the system waits for another keypress.

So for example I type "ABC", the timer loads the values which contain "ABC", "ABCD", "ABCDE" but does not display any of the values. Then I type "D" and it immediately shows "ABCD" and "ABCDE". The values were in the array before I typed "D" but the system does not display them without that additional keypress.

Checking mdbootstrap javascript, it looks like the keyup event is the one that shows the values so this hack seems to solve the problem:

$('#Autocomplete-edit-field').keyup();


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.6.1
  • Device: Notebook
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes