J4 Issue ? ?
avatar Ruud68
Ruud68
14 May 2021

Steps to reproduce the issue

In Users > Fields create 3 custom fields: test 1, test 2, test 3 (e.g. type text)
when looking in the fields table you can see that all of them have set the ordering field to 0

now click on the sort column header to start sorting
drag test 1 to position 2

the displayed sort order is now:
test 2
test 1
test 3

now press f5 to refresh the screen
the sort order now is:
test 2
test 3
test 1

Expected result

the values in the ordering field should be set to the correct sort order:
test 1 > 2
test 2 > 1
test 3 > 3

Actual result

the values in the ordering field are not set to the correct sort order
test 1 > 3
test 2 > 1
test 3 > 2

System information (as much as possible)

tested with todays (2021-05-14) nightly
php 8.0.5
mysql 8.0.25

avatar Ruud68 Ruud68 - open - 14 May 2021
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 May 2021
avatar brianteeman
brianteeman - comment - 14 May 2021

confirmed - something weird going on there

avatar himanshu007-creator
himanshu007-creator - comment - 15 May 2021

confirmed issue

avatar joeforjoomla
joeforjoomla - comment - 15 May 2021

Confirmed, applies to core and also third-party extensions

avatar joeforjoomla
joeforjoomla - comment - 15 May 2021

The problem is that the dragged element is always POSTed as the last one having the max order value
order[]: 16
cid[]: 30

avatar joomdonation
joomdonation - comment - 15 May 2021

@Fedik or @dgrammatiko Could you please take a look? It seems the dragged row is also counted, so on this line https://github.com/joomla/joomla-cms/blob/4.0-dev/build/media_source/system/js/draggable.es6.js#L54 , rows contains more than one element than it should

Change this line https://github.com/joomla/joomla-cms/blob/4.0-dev/build/media_source/system/js/draggable.es6.js#L64 to

for (i = 0, l = rows.length - 1; l > i; i += 1) {

would fix the issue. But I guess it is not the right fix.

avatar chmst chmst - change - 15 May 2021
Labels Added: J4 Issue ?
avatar chmst chmst - labeled - 15 May 2021
avatar chmst chmst - labeled - 15 May 2021
avatar dgrammatiko
dgrammatiko - comment - 15 May 2021

@joomdonation looking good, probably I should go back to elementary school and relearn counting ?

avatar joomdonation
joomdonation - comment - 15 May 2021

@dgrammatiko No, your original code looks good. The issue we are having here is somehow, related to how dragula works. If we have table with 3 rows for example, that querySelectorAll methods 4 rows. I can only guess that dragula create one extra element which is used for drag and drop and that's the reason querySelectorAll return one extra row.

In short, you do not have to go back to elementary school :D.

avatar dgrammatiko
dgrammatiko - comment - 15 May 2021

The issue we are having here is somehow, related to how dragula works.

Yes and no, the function getOrderData is getting the elements on the drop event which of course will include the extra DOM element that draggula is creating for the dragging effect. One option is to have the length shortened by one, as you're doing, or query the rows at the beginning of the script (when there's no shadow/extra element). Both ways are fine

avatar joomdonation
joomdonation - comment - 16 May 2021

Thanks @dgrammatiko . I tried to query the elements from outside, for some reasons, it is not working. So I choose the easy way by shortened by one, it works. Please test PR #33909.

avatar joomdonation joomdonation - close - 16 May 2021
avatar joomdonation joomdonation - change - 16 May 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-05-16 04:51:55
Closed_By joomdonation
Labels Added: ?
Removed: ?

Add a Comment

Login with GitHub to post a comment