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

jquery issue with drag & drop sorting #109

Closed
litobro opened this issue Sep 11, 2018 · 5 comments · Fixed by #110
Closed

jquery issue with drag & drop sorting #109

litobro opened this issue Sep 11, 2018 · 5 comments · Fixed by #110

Comments

@litobro
Copy link

litobro commented Sep 11, 2018

When trying to drag and drop using latest Django I encounter this error in my browser console when attempting to drag an drop:

TypeError: t.parentsUntil(...).size is not a function[Learn More] 69 jquery.ui.nestedsortable.js:27:20

I believe this is due to size being removed in jquery 3 and length should be used instead.

I am using django 2.1.1 and django-nested-admin 3.1.2

@dominem
Copy link

dominem commented Dec 12, 2018

I have encountered a similar issue. Therefore I think we should re-open it.

I am not able to drop a dragged parent inline.

Django==2.1.4
django-nested-admin==3.1.2

Admin classes:

class IngredientInline(nested.NestedTabularInline):
    model = models.Ingredient
    extra = 0
    sortable_field_name = 'position'


class IngredientCategoryInline(nested.NestedStackedInline):
    model = models.IngredientCategory
    extra = 0
    sortable_field_name = 'position'
    inlines = (IngredientInline,)


@admin.register(models.Recipe, site=site)
class RecipeAdmin(nested.NestedModelAdmin):
    readonly_fields = ('published_at', 'author')
    inlines = (IngredientCategoryInline,)

    def save_model(self, request, obj, form, change):
        if obj.author_id is None:
            obj.author = request.user
        obj.save()

The same issue with stacked inline for IngredientCategoryInline.

Works great for IngredientInline, but not for the parent inline.

Log from Console (the error occurs while trying to drop):

jquery.ui.nestedsortable.js:27 Uncaught TypeError: t.parentsUntil(...).size is not a function
    at HTMLTableElement.<anonymous> (jquery.ui.nestedsortable.js:27)
    at Function.each (jquery.js:354)
    at jQuery.fn.init.each (jquery.js:189)
    at jQuery.fn.init.function.n.fn.nearest.n.fn.nearest (jquery.ui.nestedsortable.js:25)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._clearEmpty (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:51497)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._clearEmpty (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:5037)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._mouseStop (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:50585)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._mouseStop (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:5037)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._mouseUp (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:12848)
    at n.(:8000/panelik/core/recipe/3/change/anonymous function).(anonymous function)._mouseUp (http://localhost:8000/static/nested_admin/dist/nested_admin.min.js:16:5037)
(anonymous) @ jquery.ui.nestedsortable.js:27
each @ jquery.js:354
each @ jquery.js:189
function.n.fn.nearest.n.fn.nearest @ jquery.ui.nestedsortable.js:25
_clearEmpty @ jquery.ui.nestedsortable.js:528
(anonymous) @ jquery.ui.djnsortable.js:21
_mouseStop @ jquery.ui.nestedsortable.js:457
(anonymous) @ jquery.ui.djnsortable.js:21
_mouseUp @ jquery.ui.djnsortable.js:21
(anonymous) @ jquery.ui.djnsortable.js:21
_mouseDistanceMet._mouseDelayMet._mouseUpDelegate @ jquery.ui.djnsortable.js:21
dispatch @ jquery.js:5183
elemData.handle @ jquery.js:4991

Screenshot:
2018-12-12

Maybe I will have some time to investigate this issue and provide a fix, but chances are small.
Thanks.

@fdintino
Copy link
Member

@dominem is it possible you have an old version of the nested-admin javascript from a previous collectstatic?

@dominem
Copy link

dominem commented Dec 13, 2018

@fdintino No, it is not possible. First of all, I have quite fresh OS installation. Secondly, this is a brand new django project. I have also disabled cache in Chrome, and the same error occurs.

(venv) C:\Users\domin\dev\zgotujprzepis>pip install django-nested-admin==3.1.2 --no-cache-dir
Collecting django-nested-admin==3.1.2
  Downloading https://files.pythonhosted.org/packages/f6/96/6d6535c8ebec7d7eec8c284b8ce2afc3128b8682365df21020c683681f8f/django_nested_admin-3.1.2-py2.py3-none-any.whl (343kB)
    100% |████████████████████████████████| 348kB 4.6MB/s
Requirement already satisfied: python-monkey-business>=1.0.0 in c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages (from django-nested-admin==3.1.2) (1.0.0)
Requirement already satisfied: six>=1.7.0 in c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages (from python-monkey-business>=1.0.0->django-nested-admin==3.1.2) (1.12.0)
Installing collected packages: django-nested-admin
  Found existing installation: django-nested-admin 3.1.1
    Uninstalling django-nested-admin-3.1.1:
      Successfully uninstalled django-nested-admin-3.1.1
Successfully installed django-nested-admin-3.1.2
(venv) C:\Users\domin\dev\zgotujprzepis>pip freeze
backcall==0.1.0
colorama==0.4.1
decorator==4.3.0
Django==2.1.4
django-nested-admin==3.1.2
ipython==7.2.0
ipython-genutils==0.2.0
jedi==0.13.1
parso==0.3.1
pickleshare==0.7.5
prompt-toolkit==2.0.7
psycopg2==2.7.6.1
Pygments==2.3.0
python-monkey-business==1.0.0
pytz==2018.7
six==1.12.0
traitlets==4.3.2
wcwidth==0.1.7

Huh... Thanks! While writing this comment I came up with an idea. What if the https://files.pythonhosted.org/ cached the version? I have noted that this fix is not versioned, so it may be possible it uses an older commit for version 3.1.2. I have checked that out, and yes it is.
I have just installed this package via git@specific commit:

(venv) C:\Users\domin\dev\zgotujprzepis>pip uninstall django-nested-admin --no-cache-dir
Uninstalling django-nested-admin-3.1.2:
  Would remove:
    c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages\django_nested_admin-3.1.2.dist-info\*
    c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages\nested_admin\*
Proceed (y/n)? y
  Successfully uninstalled django-nested-admin-3.1.2

(venv) C:\Users\domin\dev\zgotujprzepis>pip install git+https://github.com/theatlantic/django-nested-admin.git@599b539e5cecfe6c01936204f5f75ea73a419636 --no-cache-dir
Collecting git+https://github.com/theatlantic/django-nested-admin.git@599b539e5cecfe6c01936204f5f75ea73a419636
  Cloning https://github.com/theatlantic/django-nested-admin.git (to revision 599b539e5cecfe6c01936204f5f75ea73a419636) to c:\users\domin\appdata\local\temp\pip-req-build-l91yxjrj
Requirement already satisfied: python-monkey-business>=1.0.0 in c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages (from django-nested-admin==3.1.2) (1.0.0)
Requirement already satisfied: six>=1.7.0 in c:\users\domin\dev\zgotujprzepis\venv\lib\site-packages (from python-monkey-business>=1.0.0->django-nested-admin==3.1.2) (1.12.0)
Installing collected packages: django-nested-admin
  Running setup.py install for django-nested-admin ... done
Successfully installed django-nested-admin-3.1.2

Now it works, thanks!

I have a question - Why did not you bump up version after committing these changes? 😅

@fdintino
Copy link
Member

@dominem oh! I had assumed there was a new version released. I'll release 3.1.3 with this fix.

@dominem
Copy link

dominem commented Dec 15, 2018

@fdintino Great! Thanks!

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

Successfully merging a pull request may close this issue.

3 participants