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

How to fix the conflict with django-jet?

Open gotounix opened this issue 6 years ago • 7 comments

conflict

There are two select2 fields when use it in django-jet.

gotounix avatar Jun 06 '18 17:06 gotounix

What happens if you disable autocomplete of django-jet ?

jpic avatar Jun 08 '18 16:06 jpic

I also have the same problem. I disabled autocomplete of django-jet according to this instruction http://jet.readthedocs.io/en/latest/autocomplete.html#disabling-autocomplete-for-form-fields --> doesn't work, still duplicate select2 fields.

any other solution?

django==2.0.5 django-jet==1.0.7 django-autocomplete-light==3.2.10

anwarirl avatar Jul 11 '18 08:07 anwarirl

What happens if you disable both DAL and jet autocomplete ? Do you get a normal select field ?

jpic avatar Jul 11 '18 10:07 jpic

In the same django app, I have another form that didn't use DAL, and it show jet select field (autocomplete) correctly.

anwarirl avatar Jul 11 '18 12:07 anwarirl

What happens if you disable both DAL and jet autocomplete ? Do you get a normal select field without select2 ? ie. plain html

jpic avatar Jul 12 '18 12:07 jpic

I had the chance to fix this in a project today, it was like: copy jet's bundle.min.js for override, replace find("select").trigger("select:init") with find("select:not([data-autocomplete-light-function])").trigger("select:init")

The tradeoff:

  • no django-jet template
  • no edit/add buttons (but django-addanother should work)
  • need to re-patch every bundle.min.js update

It's going to be hard to do any better, given that DAL and Jet both have their initialization functions. The other way around would be to define a new autocomplete js initialization that does not create a new autocomplete, but rather, reconfigures the one created by django-jet.

jpic avatar Apr 02 '19 00:04 jpic

Another option is:

admin config:

@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
          class Media:
                 css = {"all": ("your-model.css",)}

your-model.css:

.select2-container--default + .select2-container--jet {
    display: none;
}

and jet theme select2 is hidden if it's a sibling of django-autocomplete-light select2

garyrvaz avatar Dec 18 '20 12:12 garyrvaz