0

autocomplete-light. Can any one help me. I want to show button 'add' if autocomplite return nothing (Object does not exists yet). Where can I check what get autocomplite from back-end.

Something like this

$('#myauto_field').yourlabsAutocomplete({
    fetch: function() { //Override fetch function
        //call fetch from jQuery
        //get data and see is it empty or note. If empty show button. 
    }
})

Thank you very much.

Bahtiyor
  • 1
  • 1

2 Answers2

0

There's an example in test_project (which I just did for fun), try it in /admin/ajax_create/creatable/add/. It's maybe not the best way and maybe not exactly what you want, but it sure is a really good start. You can test it here. You can easily adapt it to your exact specifications by bloating the javascript.

Instead, I'd recommend just using add-another.

jpic
  • 32,891
  • 5
  • 112
  • 113
  • ['here'](http://jpic.pythonanywhere.com/admin/ajax_create/creatable/add/) can't login with login: test, pass: test – Bahtiyor Apr 11 '13 at 11:36
  • Well I can login with test/test. Maybe you did it wrong ? Anyway, you could also [install the test_project in a temporary virtualenv locally](http://django-autocomplete-light.readthedocs.org/en/latest/demo.html) – jpic Apr 11 '13 at 17:38
0

May be this help's some one to save some time. My solution is: Add this.input.trigger('fetch', jqXHR); to autocomplite.js function yourlabs.Autocomplete.prototype.fetchComplete and put bind fetch for autocomplite input field

$('#' + fieldid).yourlabsAutocomplete({})
     .input.bind('fetch', function(e, replay){
           if(replay.responseText.indexOf("No matches found") == -1){
              //Here code if object not found
           }
});
Bahtiyor
  • 1
  • 1