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

how do we provide a createTag callback #1194

Closed morenoh149 closed 3 years ago

morenoh149 commented 4 years ago

Hello, I tried customizing the javascript loading as described at https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#overriding-javascript-code

but I do not see how to provide a callback for the createTag event as described at https://select2.org/tagging#customizing-tag-creation

Any help?

my code

# forms.py
class TickerWidget(autocomplete.ListSelect2):
    autocomplete_function = "ticker_autocomplete_init"

class CompanyForm(forms.ModelForm):
    class Meta:
        model = Company
        fields = ["ticker"]
        widgets = {
            "ticker": TickerWidget(
                url="tickers",
                attrs={
                    "data-ajax-delay": "250",
                    "required": True,
                    "data-tags": "true",
                },
            )
        }
// app.js
document.addEventListener('dal-init-function', function () {
  yl.registerFunction( 'ticker_autocomplete_init', function ($, element) {
      var $element = $(element);
      // autocomplete function here
      console.log('I dont see this');
  });
})
morenoh149 commented 3 years ago

@jpic I have a fuller example at https://github.com/morenoh149/djangox-autocomplete-light also mentioned it on the stackoverflow https://stackoverflow.com/questions/64684058/how-to-createtag-in-django-autocomplete-light?noredirect=1#comment114372622_64684058

morenoh149 commented 3 years ago

this was fixed with a full solution at https://github.com/morenoh149/djangox-autocomplete-light