yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.8k stars 467 forks source link

Overriding templateResult / templateItem functions? #739

Open wetneb opened 8 years ago

wetneb commented 8 years ago

Hi, I wonder whether there could be a cleaner way to override templateResult and templateItem callbacks without changing the whole init callback as described here: https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#overriding-javascript-code Thanks a lot for your work!

jpic commented 8 years ago

Perhaps we could refactor the init callback to make it easier ?

Have you been happy with your init callback override ?

wetneb commented 8 years ago

Refactoring the init callback would be very useful indeed! My own override involved duplicating quite a lot of code, so no, I can't really say I am happy with my current solution.

jpic commented 8 years ago

Sounds ok for me, looking forward to review your patch proposal !

morenoh149 commented 3 years ago

can we get a fuller example of overriding the init?

document.addEventListener('dal-init-function', function () {
    yl.registerFunction( 'select2', function ($, element) {
        // autocomplete function here
    });
})

What do you put in the middle? something like

$('#my-select').select2({
  createTag: function() { console.log('test'); }
});

?