Topic: Autocomplet is not working in Modal

Yutaka priority asked 3 years ago


I'm trying to use an "input" with autocomplete function inside in a modal but it does not show the list of elements to autocompleted.The autocomplete function only works if it is out of the modal.

This is my HTML code...

    <meta name="viewport" content="width=device-width" />
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
            Launch demo modal
        <div class="modal fade ui-front" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                        <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
                    <div class="modal-body ui-front">
                        <div id="basic" class="form-outline">
                            <input type="text" id="form1" class="form-control" />
                            <label class="form-label" for="form1">Example label</label>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">
                        <button type="button" class="btn btn-primary">Save changes</button>


<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Content/MDB-UI-KIT-Pro-Essential-2.0.0/js/mdb.min.js"></script>

<script type="text/javascript">
    const basicAutocomplete = document.querySelector('#basic');
    const data = ['One', 'Two', 'Three', 'Four', 'Five'];
    const dataFilter = (value) => {
        return data.filter((item) => {
            return item.toLowerCase().startsWith(value.toLowerCase());

    new mdb.Autocomplete(basicAutocomplete, {
        filter: dataFilter

This is a capture of my view...This is a capture of my view...

Andrew Ford priority answered 3 years ago

Your script tags should be right before the closing <body> tag, instead of after the closing <html> tag. And the autocomplete initialization should get wrapped in the event.

Working snippet -

Yutaka priority commented 3 years ago

Thank you, it works :)

joelgrondrup free commented 3 years ago

Was also looking for this problem to be solved. Would have been nice to notice in the docs.

Please insert min. 20 characters.


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



Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: 2.0.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No