V
V
Valeriy19972015-09-09 09:30:06
JavaScript
Valeriy1997, 2015-09-09 09:30:06

How can I limit the output of the autocomplect plugin?

I'm using the utocomplect autofill plugin. I need to limit the output to 5 results (not the output itself, but the number of tags generated by the plugin) That is, I need to limit the output that falls into the dom. I didn't find how to do it in the plugin itself. Who faced tell me how to solve?

All the code to make it clear what I'm talking about (you need to enter the letter "l") : jsfiddle.net/t52ka/75

Here is my code

$("#myinput").autocomplete({
        minLength: 0,
        source: function(request, response) {
            var term = $.trim(request.term);
            var reg = new RegExp($.ui.autocomplete.escapeRegex(term), "i");
            if (term !== "") {
                response($.grep(projects, function(tag) {
                    return tag.label.match(reg);
                }));
            }
        },
        focus: function (event, ui) {
            $("#myinput").val(ui.item.label);
            return false;
        },
        select: function (event, ui) {
            $("#myinput").val(ui.item.label);
            $("#myinput-id").val(ui.item.value);
            $("#myinput-description").html(ui.item.desc);
            $("#myinput-icon").fadeOut('slow', function () {
                $(this).attr("src", "images/" + ui.item.icon).fadeIn('slow');
            });

            return false;
        }
    })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey K., 2015-09-09
@Valeriy1997

For example stackoverflow.com/questions/7617373/limit-results-...
Well, or limit the height through CSS: jqueryui.com/autocomplete/#maxheight

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question