django-autocomplete-light icon indicating copy to clipboard operation
django-autocomplete-light copied to clipboard

Overriding templateResult / templateItem functions?

Open wetneb opened this issue 8 years ago • 4 comments

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!

wetneb avatar Sep 16 '16 17:09 wetneb

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

Have you been happy with your init callback override ?

jpic avatar Sep 26 '16 08:09 jpic

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.

wetneb avatar Sep 26 '16 08:09 wetneb

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

jpic avatar Sep 26 '16 22:09 jpic

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

?

morenoh149 avatar Oct 23 '20 17:10 morenoh149