Problem when using autocomplete, Jquery-ui

0

The information brings it to me correctly and verifies by consola , my problem is, because I get those lines as if I wanted to show the information but has nothing, someone knows what is happening ?.

$('#auto_tag').autocomplete({
    source: function(request,response){
        $.ajax({
            url: uri+'/tags',
            type: "post",
            dataType: "json",
            data:{keys: request.term},
            success: function(data){
                response(data);
                console.log(data);
            }
        });
    },
    minLength: 1,
    select: function(event,ui){
        data = ui.item.id+'*'+ui.item.name;
        $('#button-a-tag').val(data);
    },
});
    
asked by DoubleM 17.06.2018 в 02:37
source

1 answer

0

I had the same problem, in my case it was that the action that returned the elements to show in the autocomplete had a bad format. Said "format" can be given in the Select (). I do not know how to explain it, but I'll put the code for how I return the info.

var resultado = db.TBL_PRODUCTOS.Where(x => x.DESCRIPCION.Contains(term)).Where(x => x.ESTATUS == true).Select(x => new { label = x.DESCRIPCION, value = x.DESCRIPCION+"|"+x.ID_PRODUCTO }).ToArray();
            return Json(resultado, JsonRequestBehavior.AllowGet);

I use lambda expressions for my queries, in the Select create an anonymous object and the most important thing is that you must have a property that is called LABEL and another that is called VALUE. Where LABEL is the autocomplete suggestion and VALUE is what your textbox will be filled with

By giving it that "format" I corrected the error.

I hope and serve you. By the way, it's the first time I publish.

    
answered by 29.09.2018 в 08:05