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

linked data and clean script $ is not a function

Open maltalk opened this issue 3 years ago • 5 comments
trafficstars

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

maltalk avatar Nov 30 '21 15:11 maltalk

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 avatar Dec 02 '21 08:12 jpic

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

jpic avatar Dec 02 '21 08:12 jpic

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

maltalk avatar Dec 03 '21 10:12 maltalk

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.

jpic avatar Dec 03 '21 14:12 jpic

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).

mnieber avatar Jul 29 '22 17:07 mnieber