Can’t get the jQueryUI autocomplete to work with the mouse (autocomplete input is in bootstrap modal form). Only works when selecting with the keyboard, while selecting with the mouse is completely ignored.
Here is sample code with this bug:
(Loaded CSS/JS libraries: bootstrap 5, jQuery, jQuery UI, FontAwesome)
Bootstrap modal form popup.
<div class="container py-3">
<button type="button" data-bs-toggle="modal" data-bs-target="#myModal" class="btn btn-primary">Open modal</button>
</div>
<!-- Modal popup -->
<div class="modal" tabindex="-1" id="myModal">
<div class="modal-dialog">
<form action="post" action="#" id="acModalForm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit form</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h1>Form</h1>
<hr>
<div class="form-floating">
<input type="text" class="form-control" id="acInput" placeholder="Sample autocomplete value" value="">
<label for="acInput">Sample autocomplete value</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
Autocomplete Javascript
$(function () {
const sampleData = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ];
$("#acInput").autocomplete({
source: sampleData,
appendTo: "#acModalForm"
});
});
Is there some fix to this "bug"?
Any help is appreciated
2
Answers
you can set wrong id to append data so autocomplete data mouse selection not working you can set model id to work.
Change code
To
Per the Docs:
I would suggest adding the
ui-front
class to your Modal: