Comments

BarisW created an issue. See original summary.

BarisW’s picture

Version: 8.x-3.x-dev » 8.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new955 bytes

Here's a patch that implements this.

BarisW’s picture

StatusFileSize
new1.14 KB

Apologies, the patch misses the use statement.

BarisW’s picture

Not sure why the test fails, but it is not related to my patch for sure.

acrosman’s picture

On the 8.x-3.x-dev branch I'm seeing a similar behavior in that if there are any errors outside the visible tab the form does not post, nor do any errors appear. Unfortunately the current patch here (which does apply cleanly that that branch) didn't resolve the issue.

acrosman’s picture

geek-merlin’s picture

Title: Fields with errors are not visible » Fix visibility of invalid fields (serverside)
geek-merlin’s picture

Title: Fix visibility of invalid fields (serverside) » Ensure visibility of invalid fields (serverside)
chrisolof’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev
Status: Needs review » Needs work

Seems to work for top-level details elements. Anything more complex is left closed. Seems like we'd want to ensure any field group at any depth containing validation-failing elements would be rendered open.

chrisolof’s picture

Just a note that the patch in #3 applies to 8.x-3.0-beta1, but not the current 8.x-3.x branch. In attempting to improve the patch with recursion and bring it into compatibility with 8.x-3.x I found that the technique in patch #3 no longer works (looking for the presence of '#children_errors'). It seems that the error-state of form elements is no longer part of the $rendering_object/$processed_object in Drupal\field_group\FieldGroupFormatterBase or Drupal\field_group\Plugin\field_group\FieldGroupFormatter, so I guess we'll need to use a different approach or move the logic to a different spot.

chrisolof’s picture

Status: Needs work » Needs review
StatusFileSize
new2.5 KB

Turned out that 8.x-3.x deprecated the use of the pre-render callback and moved everything under the #process form callback. The properties we're after here, like '#children_errors', only appear in the pre-render callback.

The attached patch registers a pre-render callback function for forms with fieldgroups and in that callback function opens any fieldgroups that contain elements with errors. This patch is fieldgroup type agnostic and will work with any fieldgroup that sports an "#open" property.

To test in a form, be sure to turn off client-side validation as that's still a work-in-progress (see #2787179: Ensure visibility of invalid fields (JS)). In a form alter hook you can add:

$form['#attributes']['novalidate'] = 'novalidate';

This is ready for review.

daniel kulbe’s picture

Status: Needs review » Fixed

The patch seems to be applied to the current version.

daniel kulbe’s picture

Status: Fixed » Needs work

Sry, was mistaken. This simply cannot be applied to RC1.

kell.mcnaughton’s picture

daniel kulbe’s picture

Rerolled patch from #14

mekal’s picture

It seems patch #15 breaks the node/add/ page in drupal 9.0.3 with both field_group 3.1 and 3.1-dev.

Drupal\Core\Security\UntrustedCallbackException: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was field_group_form_pre_render. See https://www.drupal.org/node/2966725 in Drupal\Core\Render\Renderer->doTrustedCallback() (line 96 of core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php).

Drupal\Core\Render\Renderer->doCallback('#pre_render', 'field_group_form_pre_render', Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
...etc

This line in the patch seems to be the culprit:
$form['#pre_render'][] = 'field_group_form_pre_render';

And here are two issues that might be relevant:
https://www.drupal.org/project/field_group/issues/3109552#comment-13580989
https://www.drupal.org/project/field_group/issues/3147495#comment-13680974

mekal’s picture

StatusFileSize
new69.95 KB
new195.72 KB

Patch #15 also has an issue on the node create page on 8.9.1 - 8.9.9.
I appears that if a tab has a required field in a tab and the "Mark group as required if it contains required fields." setting is enabled for that tab, then all the fields in that tab will be hidden when you first go to create a new page (node/add/page).

But if you try to submit the form, the fields will appear, along with the required field message(s).
So you can still make it through the process of creating the page, but its definitely not ideal.

See screenshots:
empty-tab-on-page-load.png : The node/add/page form when its first loaded.
empty-tab-after-save.png: And after you hit the save button.

daniel kulbe’s picture

Updated the patch for D9 compatibility.

daniel kulbe’s picture

StatusFileSize
new3.17 KB

Fixed the undefined function call.

daniel kulbe’s picture

StatusFileSize
new3.17 KB
joshua.boltz’s picture

This may help someone else, but I also tried things like using latest 3.x-dev as specified in https://www.drupal.org/project/field_group/issues/3109552#comment-13554032, yet the error was still occurring.

It turns out that my codebase was using this patch:
https://www.drupal.org/project/field_group/issues/2894213#comment-13683617

Which that patch adds some of the pre_render logic that is now an issue in D9.

I found the solution to fix this issue was when I stumbled upon:
https://www.drupal.org/project/field_group/issues/2894213#comment-14008160

Which updates that patch to be D9 supported. Basically converts the pre_render callback to an TrustedCallbackInterface instance like the error states.

livnluvnit’s picture

Ive been researching this for about a week now and so far Joshua's step gave me hope but error continues to appear. I am running Drupal 8.9.13

Drupal\views\Entity\Render\EntityFieldRenderer->render(Object, Object) (Line: 846)
Drupal\views\Plugin\views\field\EntityField->getItems(Object) (Line: 312)
Drupal\search_api\Plugin\views\field\SearchApiEntityField->getItems(Object) (Line: 1148)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 238)
template_preprocess_views_view_field(Array, 'views_view_field', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('views_view_field', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 1746)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 771)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 710)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array) (Line: 577)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, 1) (Line: 468)
Drupal\views\Plugin\views\style\StylePluginBase->render(Array) (Line: 2170)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 131)
Drupal\webprofiler\Views\TraceableViewExecutable->render() (Line: 138)
Drupal\views\Plugin\views\display\Block->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('block_1', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 59)
Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 105)
Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object) (Line: 76)
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch('section_component.build.render_array', Object) (Line: 90)
Drupal\layout_builder\SectionComponent->toRenderArray(Array, ) (Line: 86)
Drupal\layout_builder\Section->toRenderArray(Array) (Line: 317)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Object) (Line: 276)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 351)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 293)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 76)
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
styrbaek’s picture

The patch not fixing the issue for me.
Drupal 9.1.6

bohus ulrych’s picture

I've also spend some time trying to find solution for this error. I'm using Drupal 9.1.9 with patch #20.

My problem was caused by another module - paragraphs, with patch "Field group support broken" https://www.drupal.org/project/paragraphs/issues/3138609. As you can see in the comment #35 https://www.drupal.org/project/paragraphs/issues/3138609#comment-13934356 this patch uses call for field_group_form_pre_render() - and this is problem.

So search in you modules folder for modules calling field_group_form_pre_render() and try to remove it.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Thank you Joshua— as Bohus notes if you this doesn't fix the error look for additional modules/patches using field_group_form_render. Daniel's latest patch does fix the problem here.

In other news this patch is still fixing the original issue to and i think is RTBC.

nils.destoop’s picture

Status: Reviewed & tested by the community » Fixed

Thx for the patch. I tested it and confirmed to be working.
I modified it a bit, to still have BC support for modules that are using the field_group_form_pre_render instead of the process method. Otherwise field_group would be broken for those modules.

Status: Fixed » Closed (fixed)

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