Autocomplete materialize by closing

Asked

Viewed 62 times

0

Friends someone knows how to solve the following problem, the materialize autocomplete, does not show when completing the lenght, but when clicking again on the input it opens and closes quickly without selecting anything, it is being populated with the data, I am using version 1.0.0 of materialize and jquery 3.3.1. Any idea how to solve it? Thank you.

$(document).on('input', 'input.autocomplete', function() {
    let im = $(this).val();
    var base_url = '<?php echo base_url() ?>';
    var url = "<?php echo site_url('/pesquisa/imobiliarias')?>";
    $.post(url, {
        im: im
    }, function(suggestions) {
        var Array = JSON.parse(suggestions);
        var List = {};
        for (var i = 0; i < Array.length; i++) {
            List[Array[i].im] = Array[i].flag;
        }
        $('input.autocomplete').autocomplete({
            data: List,
            limit: 20,
            minLength: 2
        });
    });
});

On the controller:

function imobiliarias(){
    $im = $this->input->post('im');
    echo json_encode($this->Model_pesquisa->imob($im));
}

No Model:

function imob($im) {
    $this->db->select('im');
    $this->db->like('im', $im);
    $this->db->from('entrega');
    $this->db->group_by('im');
    $this->db->order_by('im', 'asc');
    $query = $this->db->get();
    if ($query->num_rows() >= 1) {
        return $query->result_array();
    }
}

On the console.log

{"Cia do imóvel ": undefined, Roca Imóveis: undefined}
  • I noticed that you do not have the php file, it would be real estate.php, could put the JSON example that you are returning??

  • I edited with the returns

  • It populates the auto complete only I have no idea of the pq it closes...

  • The console.log is before var Array = JSON.parse(suggestions);' ?? puts the console.log(suggestions) before it and posts its result.

  • [{"im":"Cia do im u00f3vel "},{"im":"Roca Im u00f3veis"}] este é o antes do json.parse

  • After the information you passed on, I was able to reproduce and did not have this failure!!

  • I’ve tried other ways and the same, in version 0.100 it works normal but in this no, I can not downgrade the version of materialize has a lot q does not work in this version

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.