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.79k stars 467 forks source link

linked data and clean script $ is not a function #1272

Open maltalk opened 2 years ago

maltalk commented 2 years ago

When trying to use linked_data funcionality the clean forward field script is showing an error and is not working as it should: $ is not a function. Here is the example with the DAL master branch (and test project) but also happens with the version 3.8.2 of the package.

image

Python version: 3.8.10

Dependencies: image

jpic commented 2 years ago

Right, thanks for your report!

This seems to be because DEBUG is True, can you confirm this?

I really want to move to ESM so I'm going to try that, already opened an issue on Django about it.

jpic commented 2 years ago

@danielmorell any opinion about this btw? thank you <3

maltalk commented 2 years ago

I'm sorry to tell you that when setting DEBUG=False the server stops serving the media files so i could not confirm this.

jpic commented 2 years ago

Alright, apparently the problem is just that jQuery is not loaded as $ in the global namespace, I could fix it by adding this at the top of linked_data.js:

$ = django.jQuery

Not sure if that's great though.

mnieber commented 2 years ago

It seems that linked_data.js was fixed by adding the line $ = django.jQuery as mentioned above. However, there are some issues:

  1. The fixed version still crashes (in my case) because django.jQuery is only defined when the document is ready. So the fix doesn't achieve its goal (the script now crashes on line 2)
  2. More importantly, afaict, the linked_data script is obsolete. I'm not sure what it's trying to do (the select statement in this script looks suspicious, because it doesn't seem to target any elements that are on the page), but the linked_data example works also without this script (this is not surprising, because the script was already crashing).

I even suspect that keeping this script may cause problems, because in my case, the dynamic selection behaviour started working once I removed this script (however, I cannot exclude the possibility that some other change fixed it).