简体   繁体   中英

django-autocomplete-light on fetch data

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.

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.

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
           }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM