Skip to content

How to limit the number of values shown for autocomplete field? #36

@nicolazilio

Description

@nicolazilio

First of all, I'd like to say good job on creating DjangoQL! It's a great app.

I have a quick question about your autocomplete function. I use it to show suggestions for a field that has many possible values (>1000), like so

class SearchFieldOptPartDescription(StrField):
    """Create a list of unique part descriptions for search"""

    model = order_management_Order
    name = 'part_description'
    suggest_options = True

    def get_options(self):
        return super(SearchFieldOptPartDescription, self).\
        get_options().all().distinct()

I wonder if you could point me in the right direction as to how I could reduce the number of shown options to, let's say, the top 10 after a person has started typing 3 letters. Right now, it shows all available values right from the start.

For example for jquery autocomplete function I would use slice(), like so

$('#id_part_description').autocomplete({
            source: function(request, response) {
                    var results = $.ui.autocomplete.filter(product_names, request.term);
                    response(results.slice(0, 10));

I suspect I would have to change DjangoQL's javascript to accomplish this. But I don't know where to find the relevant lines of code that I need to modify.

Thanks a lot in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions