So one problem with drag and drop is that if you move a field or a field group outside a group above the group, the parent is not reset to none. It seems to happen only if you move it to the top of the table.

To reproduce

  1. Create a tabs group and put it on top of the table
  2. Create a tab group and nest this underneath
  3. Nest a field, say the body, under the tab and save
  4. Now drag the body to the top of the table, in the root. Then hit 'Show row weights'. The parent will still be the first tab

Note: after some tests, a simple single group, say details, is good enough to to reproduce this bug! See the small video underneath to see how to reproduce it.

Parent not resetting

It looks like that is fixed in #3089151: TableDrag JS :first-of-type issues.

Other things:

  • Tabs also sometimes act weird.
  • I was able to get to a state as well where no region value was set for a field, becoming empty.

Not sure yet how to reproduce these two consistently, will document more when I can.

So this seems like a core problem. But let's see if we can we fix this ourselves as this makes it very tedious to drag and drop groups in general. If you comment out line 332 of includes/field_ui.inc (the library), you hit the same bugs.

Comments

swentel created an issue. See original summary.

swentel’s picture

Title: Drag and drop acts weird » Drag and drop acts weird, sometimes not resetting the parent
swentel’s picture

Issue summary: View changes
swentel’s picture

Issue summary: View changes
swentel’s picture

So I do really thing this is a problem with core tabledrag js. The annoying thing is that I can't find any implementations in core that use an explicit parent select field for now. Are there other contrib modules that do this ?

swentel’s picture

Issue summary: View changes
swentel’s picture

Issue summary: View changes
swentel’s picture

Title: Drag and drop acts weird, sometimes not resetting the parent » Drag and drop acts weird, sometimes not resetting the parent, or even clearing the region value
Issue summary: View changes
swentel’s picture

Issue summary: View changes
andypost’s picture

It works but randomly fails for me(

swentel’s picture

Priority: Critical » Major
Issue summary: View changes

Confirmed this is most likely a core problem. If you uncomment $form['#attached']['library'][] = 'field_group/field_ui';, you hit the same bug with the parent not resetting. Checking if there's a core issue about it. Setting to major as this isn't directly field group's fault.

swentel’s picture

StatusFileSize
new924.74 KB

Created an animated gif so people can see the problem to reproduce. It shows how the parent is not reset when dragging a field to the top.

swentel’s picture

Issue summary: View changes
andypost’s picture

nils.destoop’s picture

Looks idd tabledrag related. If you make the js files of field_group and field_ui empty, the region is still lost when moving my tab. The region is always lost when you make a group a lvl 2 group. As long as the group stays in the root, the region is not lost.

nils.destoop’s picture

StatusFileSize
new187.71 KB

The issue seems to be related with the options given to tabledrag. When you drag something to a parent, it receives .field-name as source element, while this is the source element for parent, not for region.

Drag

If I remove the source in EntityDisplayFormBase, or set the source to field-region, everything is working on the manage form for fieldgroup. But on the display management, it is still broken in combination with DS due to js errors.

nils.destoop’s picture

nils.destoop’s picture

Also created #3087612: DS resets all the rowHandlers to field for an issue with DS.

swentel’s picture

Mmm tried the core patch but it doesn't seem to fix the issue which you can see in the animated gif at the top on manage form display. So something else is still doing something weird.

andyf’s picture

Status: Active » Needs review
Related issues: +#3089151: TableDrag JS :first-of-type issues

Hi, I noticed some issues with tabledrag selectors recently, and I think they may explain the problem here. The following code from tabledrag:1092 uses the selector tr.draggable:first-of-type to grab the first row of the table, but that fails if you have a non draggable first row (which on the node form display is the No field is displayed row).

        // Use the first row in the table as source, because it's guaranteed to
        // be at the root level. Find the first item, then compare this row
        // against it as a sibling.
        sourceRow = $(this.table)
          .find('tr.draggable:first-of-type')
          .get(0);

I think I've found a few similar errors in #3089151: TableDrag JS :first-of-type issues. From my manual testing the patch there fixes the problem here, but frustratingly I can't get the automated test to drag the second row up above the first (although I can move a row up in the weight test...).

I'm tentatively setting the status to needs review despite there not being a patch here, not 100% sure what the best approach is.

Thanks!

liquidcms’s picture

i saw this post #3064890: Notice: Undefined index: name in Drupal\field_ui\Element\FieldUiTable::reduceOrder() (line 228 of /var/www/html/docroot/core/modules/field_ui/src/Element/FieldUiTable.php) which is closed as a duplicate, possibly of this issue (but mentions another related to DS, which is not my issue).

It does seem as though Field Group latest (-rc2) is broken. I see on a node form display page that i do have FGs set up and working correctly; but trying to add a new one and i get the reduceOrder error reported in the original issue, plus i can not move it out of disabled.

I see that up until a couple weeks ago i was using -rc1; so perhaps that is why i have working FGs placed on my form. Although, i tried now going back to -rc1 and although the reduceOrder error does not show, i still cannot place the FG and i get a new error (guess due to db change required for -rc2 update).

Not sure if any point in going back to try 1.x version.

Glad to see this is marked as Major as Field Groups must be one of those "Drupal 8 release blocker" sort or modules, I would think.

andyf’s picture

Issue summary: View changes

Just a quick update: the patch in #3089151: TableDrag JS :first-of-type issues seems to fix the first issue described in the IS and shown in the gif, and since #2769825: Cannot swap tabledrag rows by dragging the lower over the upper row in tests the tests work as well. I'm not sure whether it addresses this from the IS:

  • Tabs also sometimes act weird.
  • I was able to get to a state as well where no region value was set for a field, becoming empty.

or this from #23:

Notice: Undefined index: name in Drupal\field_ui\Element\FieldUiTable::reduceOrder() (line 228 of /var/www/html/docroot/core/modules/field_ui/src/Element/FieldUiTable.php)

liquidcms’s picture

@AndyF, yes, the 2 core patches in #24, against 8.8.0, fix my issue. :)

gaëlg’s picture

For anyone facing a similar problem, here's a hint. I had field groups configured as "region: hidden" in my config yml files, despite they had "enabled" children. So that on the entity form display edit form, those groups appeared twice, in the content region and in the hidden ("Disabled") region. I changed their config to "region: content" and it fixed my ordering/weight/tabledrag problems. No other patch needed for me.

devil2005’s picture

Hi

Same problem on a fresh D10 and dev version of the module... Can't save my groups with correct order or children, they save them random in template

sergioitdo’s picture

Same problem too on a D10. I'm not abled to save the changes after order or children, they items stay on the same place.

erutan’s picture

@sergioitdo have you tried applying the following patch to core?

https://www.drupal.org/files/issues/2023-02-08/3089151-45.patch

"drupal/core": {
	"drag n drop": "https://www.drupal.org/files/issues/2023-01-10/3089151-45.patch"
},
boby_ui’s picture

#29

+1 fixed the drag and drop issue in D10 too

webmestre’s picture

Once patched, on Drupal 10.1.5, the drag'n drop works.
BUT the created structure is unstable: i.e. tabs don't stay nested as designed when re-opening the form edit page.

michaellenahan’s picture

Just in case anyone comes to this issue from google, here is a screenshot with some instructions on how to manually set the weights if drag and drop is not working for you.

https://www.drupal.org/files/issues/2025-04-28/2025-04-28-17.27.27-field...

grevil’s picture

Hey everyone, it feels like this issue got a bit off track. The issue summary including the video seem to be unrelated to the patch that is suggested as a potential fix here.
Since I wanted to preserve the conversation here, I created a separate issue, targeting the same issue. Feel free to test the patch from #3538795: Manage Display: Child fields moved from groups to "ground level" retain parent relationship in combination with the core patch from #3539083: Field UI: Parent-child relationships not properly updated when fields are moved via drag-and-drop (Field Group).

If the feedback is good, I'll close this issue as a duplicate of #3538795: Manage Display: Child fields moved from groups to "ground level" retain parent relationship, otherwise we can keep it open as a follow-up issue and adjust the issue summary. Until then, I'll set it postponed.

anybody’s picture

I agree this is probably fixed by the MR in #3538795: Manage Display: Child fields moved from groups to "ground level" retain parent relationship now, please try the patch over there and close this as duplicate, if it's fixed. The other fix is definitely the cleaner one, combined with the core fix from #3539083: Field UI: Parent-child relationships not properly updated when fields are moved via drag-and-drop (Field Group)

swentel’s picture

I'm not sure if it was really off track, as far as I can see. It's been a while since I've found the energy to dive into this one as it's tricky :) There are basically two problems (in core) with tabledrag:

- not changing the parent, tracked in #3089151: TableDrag JS :first-of-type issues. Some people report that it fixes the issue.
- (re)setting the region value, tracked in #3087608: Tabledrag is resetting the region value if items are nested - but it might be obsolete by the previous one.

Again, it's been a while, so I feel like there's actually too many issues open now, which makes it even more off track :)
Ideally, we can fix this in core. But I would be ok if we are able to fix this in field group, without having to rely on a core patch.
(it would be even better if FG just goes into core of course haha)

Note: I'm less involved nowadays, but I know this issue is tracked in couple of other issue, so I'd rather leave this one open as the 'canonical', thoughts?

(There was also a conflict of DS which gets in the way in although that should have been fixed already by #3087612: DS resets all the rowHandlers to field though)

swentel’s picture

Rereading everything again, I'm still rather a fan of fixing this in tabledrag JS and see if we can get #3089151: TableDrag JS :first-of-type issues forward (if possible of course), where, afaics, the fundamental problem lies. Only fixing it in core for field ui, would still leave problems for other UI's (although I'm not sure how many other's have nesting and multiple regions, but oh well).

Also #3333953: Nested field groups improperly display as "Disable" in the admin UI is a duplicate - where someone also reports that #3089151: TableDrag JS :first-of-type issues might fix things.

Will debug some during the weekend to get a clearer view.

andyf’s picture

@swentel if you're able to give a bit of time over to a review of #3089151: TableDrag JS :first-of-type issues I could summon the courage to get back in on the dev side. I backed off a bit because it was getting at best cursory reviews, but it'd be neat to take it over the finish line... assuming tabledrag hasn't completely changed in the meantime at least (: Completely understand if you don't have time btw, jus thought I'd mention it.

grevil’s picture

First off, I am shocked, that field_ui doesn't have a direct dependency on tabledrag.js. I was already wondering how changing the behavior of tabledrag.js would affect field_ui.js, since there is no dependency between the two.

Second, I couldn't replicate #3087608: Tabledrag is resetting the region value if items are nested at all, which got me wondering why. Turns out, the gin admin theme (which we use on all projects) provides its own tabledrag.js override, see https://git.drupalcode.org/project/gin/-/blob/5.0.x/js/overrides/tabledr....

Since gin will replace claro in the future, see https://www.drupal.org/about/core/blog/drupal-core-will-adopt-gin-admin-... and claro is currently the only theme using drupal cores tabledrag.js I wouldn't waste time fixing a file which will probably get replaced by its gin counterpart anyway.

I would suggest fixing it in gin instead, but I am still unsure what's wrong with the approach in #3539083: Field UI: Parent-child relationships not properly updated when fields are moved via drag-and-drop (Field Group)? There is already similar logic in field_ui for changing regions, so why not simply do the same when changing parents?

swentel’s picture

Apparently this happened from #3204862: Backport tabledrag.js for Drupal 8.8+. This is annoying. Not everyone uses Gin, or will use Gin in the future if it's in core (we often don't for instance).

Darn, this is annoying. It's likely safer to go forward with #3538795: Manage Display: Child fields moved from groups to "ground level" retain parent relationship then yes. We really don't want to add a dependency on an admin theme for this.

  • Re: dependency: tabledrag library is added by drupal_attach_tabledrag() which is a helper function in core.
  • Re: region value which are nested: this is probably (but I'll try to confirm over the weekend), in combination with Display Suite. It's been too long since I created this issue.
anybody’s picture