jrief / django-admin-sortable2

Generic drag-and-drop ordering for objects in the Django admin interface
https://django-admin-sortable2.readthedocs.io/en/latest/
Other
770 stars 180 forks source link

Unhandled Promise Rejection #313

Closed shacker closed 2 years ago

shacker commented 2 years ago

admin-sortable2 2.0.4 in my project works fine on localhost. But deployed to a server, the second I touch a drag handle, the console shows this error:

CleanShot 2022-05-24 at 22 58 55@2x

And ordering changes are not saved. Whatever t is, it's undefined! I've confirmed that /static/adminsortable2/js/adminsortable2.min.js is definitely loading, with a 200.

Is this a bug, or could I have misconfigured something?

shacker commented 2 years ago

No one else is encountering this? Any theories?

Eccleshall commented 2 years ago

@shacker This appears to be an issue with the minified version (adminsortable2.min.js) the un-minified version works as expected.

As a temp work around add below code to your admin class that inherits SortableAdminMixin which will remove min from the file path name which is applied when DEBUG = False as per SortableAdminBase - adminsortable2/admin.py line 66.

    @property
    def media(self):
        css = {"all": ["adminsortable2/css/sortable.css"]}
        js = ["adminsortable2/js/adminsortable2.js"]
        return super().media + widgets.Media(css=css, js=js)
jrief commented 2 years ago

@Eccleshall thanks for looking at this problem. What do you think, shall I refer to the unminimized version only?

shacker commented 2 years ago

@Eccleshall @jrief Thanks for the confirmation! I can live with the workaround until the next release. Cheers!

christianwgd commented 2 years ago

Simply copying the unminified version over the minified also works fine and doesn't need code changes. When a release with a fix is available manage.py collectstatic will switch back to the minified version (assuming the next version contains a fix, thought 2.0.5 would do, but seems not).

jrief commented 2 years ago

Minimizing the JS file has been built into the deployment script. I hope this will fix it.

christianwgd commented 2 years ago

Sorry to say, updated to 2.1.2, but this issue still appears. After copying the unminified version to the minified the error is gone. Before that i deleted the browser cache, reinstalled the library, "force updated" the site and so on.

jrief commented 2 years ago

Fixed in version 2.1.3 by using terser instead of uglify.