Search code examples
djangodjango-autocomplete-light

django-autocomplete-light add parameter to query url


I'm trying to pass some data along to the autocomplete_light.AutocompleteModelBase so I can exclude some models from the search. I'm trying to use the Dependencies info in the docs here

but I can seem to get it.

The id of the input is id_alternate_version-autocomplete, so I'm trying:

$("#id_alternate_version-autocomplete").yourlabsWidget().autocomplete.data = {'id': 'foo'};

But the url called looks like http://127.0.0.1:8000/autocomplete/FooAutocomplete/?q=bar

I want: http://127.0.0.1:8000/autocomplete/FooAutocomplete/?q=bar&id=foo

How can I do something like that?


Solution

  • This is how I did it:

    $(document).ready(function() {
        $('form#recipe').on('change propertychange keyup input paste', function() {
            var ingredient_item_type    = $("form#recipe input[type='radio']:checked").val();
            var widget                  = $("form#recipe input#id_ingredients_text").parents('.autocomplete-light-widget');
            if(ingredient_item_type) {
    widget.yourlabsWidget().autocomplete.data['hello'] = 'world';
            }
        });
    });
    

    Javascript acrobatics aside, the key observation is thus:

    anything you put in the .data object of the autocomplete widget will automatically be made part of the GET request. HTH.