Topic: Correct way to set autocomplete value
Expected behavior
What's the correct way to dynamically set an autocomplete value from jquery. The following command:
$('#form-autocomplete').val('Massachusetts')
See Snippet - It does not set the field value as if it was selected by a user. The label overlaps and the cross button doesn't show.
P.S. This would be good to add to documentation.
Thanks
Actual behavior
See snippet
Resources (screenshots, code snippets etc.)
https://mdbootstrap.com/snippets/jquery/watts/1904750
Mateusz Łubianka staff answered 5 years ago
Hi @Watts,
Try to use this code:
$('#form-autocomplete').val('Wisc').trigger('keyup').trigger('focus');
Best,
Watts commented 5 years ago
Thanks!
The final step was:
$('.mdb-autocomplete-wrap li').trigger('click')
Mateusz Łubianka staff commented 5 years ago
I'm glad I could help.
Best,
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.14.1
- Device: DESKTOP
- Browser: Chrome
- OS: Linux
- Provided sample code: No
- Provided link: Yes