Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using together with Django autocomplete fields in admin #180

Open
spechtx opened this issue Aug 5, 2022 · 3 comments
Open

Error when using together with Django autocomplete fields in admin #180

spechtx opened this issue Aug 5, 2022 · 3 comments

Comments

@spechtx
Copy link

spechtx commented Aug 5, 2022

I'm registering MyModel in the admin:

@admin.register(MyModel)
class MyModel(admin.ModelAdmin):
    search_fields = ['field_1',]
    filter_horizontal = ['phone_fk', 'email_fk',]
    formfield_overrides = {AddressField: {"widget": AddressWidget(attrs={"style": "width: 400px;"})}}
    autocomplete_fields = ['parent', ]

When autocomplete_fields is set, following error occurs:
jquery.js:4050 jQuery.Deferred exception: self.geocomplete is not a function TypeError: self.geocomplete is not a function
at HTMLInputElement. (http://127.0.0.1:8081/static/address/js/address.js:6:8)
at Function.each (http://127.0.0.1:8081/static/admin/js/vendor/jquery/jquery.js:385:19)
at jQuery.fn.init.each (http://127.0.0.1:8081/static/admin/js/vendor/jquery/jquery.js:207:17)
at HTMLDocument. (http://127.0.0.1:8081/static/address/js/address.js:2:21)
at mightThrow (http://127.0.0.1:8081/static/admin/js/vendor/jquery/jquery.js:3766:29)
at process (http://127.0.0.1:8081/static/admin/js/vendor/jquery/jquery.js:3834:12) undefined
jQuery.Deferred.exceptionHook @ jquery.js:4050
process @ jquery.js:3838
setTimeout (async)
(anonymous) @ jquery.js:3872
fire @ jquery.js:3500
fireWith @ jquery.js:3630
fire @ jquery.js:3638
fire @ jquery.js:3500
fireWith @ jquery.js:3630
ready @ jquery.js:4110
completed @ jquery.js:4120
jquery.js:4059 Uncaught TypeError: self.geocomplete is not a function
at HTMLInputElement. (address.js:6:8)
at Function.each (jquery.js:385:19)
at jQuery.fn.init.each (jquery.js:207:17)
at HTMLDocument. (address.js:2:21)
at mightThrow (jquery.js:3766:29)
at process (jquery.js:3834:12)

My guess is, the autocomplete field loads it's on jQuery for select2, and this somehow interferes...

Any idea for a workaround?

@benoitperrin
Copy link

@spechtx Thanks for pointing this out. I am running into the same issue. Have you found a workaround in your case?

@banagale
Copy link
Collaborator

There's a warning about autocomplete_fields implying custom widgets of their own in the django docs here: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides

@benoitperrin
Copy link

I was not able to find a link with the issue mentioned here. My “workaround” is not to use autocomplete_fields and AddressWidget on the same page.

IMHO, a solution here lies in the deprecation of the use of jquery in this library, as described in #139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants