I've been working on a core issue in which Form validation messages can appear in incorrect order if you have reordered fields by adjusting weights in a form alter. See #177124: Form validation messages appear in incorrect order for detail. The fix for this is to sort the elements during validation, ensuring that the validations get called in the order that the fields are actually displayed.

However, with fieldgroup installed, once the validation has failed everything that is within a fieldgroup appears below the submit buttons, right at the bottom of the form. I believe this is because in field_group_fields_nest() the group element field is simply apended to the end of the form structure, rather than being inserted at the location where it belongs.

field_group_fields_nest() should insert the field group element at the correct location within the form, and it should set the weight on the field_group so that element_children() with the sort paramater set to TRUE can function properly and retain the ordering on the field groups within the form_structure.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Attached is a test Feature module which will create add several fields and field groups to the Page content type, it also implements hook_form_alter to move one of the field form the bottom of the form, to the top.

Also attached is a patch that remedies the problem by ensuring that field group elements get inserted into the form in the correct location, with the correct weight.

To Test:

1. Apply the patch to field_group.
2. Apply the patch from #177124: Form validation messages appear in incorrect order to Drupal Core
3. Install the test feature.
4. Visit the /node/add/page
5. Submit the form leave all fields blank (they are all required)

Notice that the order of the validation matches the order of the fields as presented on the form (field_test6 is at the top in both the form and the validation errors).

Now, reverse the core patch, and notice that the order of the validation no longer matches the form (that's the core issue).

Apply the core patch again, and reverse the field_group patch. Notice that the validation is in the correct order again (thanks to core patch), but the order of the form elements has gone screwy - the field groups now appear at the bottom of the form below even the submit button. See attached screenshot.

In summary, this patch or something very similar to it is needed to make field_group play with the improved core validation system from #177124: Form validation messages appear in incorrect order.

m.stenta’s picture

Status: Needs review » Reviewed & tested by the community

I'm noticing a similar issue on my site, but not in the form... in the display. The form displays field groups in the right order, but I get inconsistent results in the display. Some of my entities display them in the right order, and others display them in a different order.

I applied the patch in #1 and it fixed my issue.

m.stenta’s picture

Status: Reviewed & tested by the community » Needs review

Scratch that. This patch did not help in my case (in the display). It reverted back to out-of-order field groups after I pushed my changes to a new server.

Stalski’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

Thx for the patch. I looked at both patches and it's ok by me.
However, if I understand correctly, the patch in #2 can only be committed once the core patch is approved.

So I suggest to leave this until that one is actually pushed in D7.

kevinquillen’s picture

The display order is also incorrect for me- even with the patch. Form seems fine.

nils.destoop’s picture

Status: Reviewed & tested by the community » Fixed

As the patch doesn't break a thing. I already committed him. The form structure should now be ok.
For people having troubles with display order. It's better to open a separate issue with more details.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

more accurate description.

  • Commit d81a85f on 7.x-1.x, 8.x-1.x authored by mrfelton, committed by zuuperman:
    Issue #1657306 by mrfelton: Fixed Field group form elements are placed...