When in a form where required fields appear in a Vertical Tab, if a field that is required isn't filled in, or skipped by accident, and another tab is accessed, the tab with the validation error is not open, which can sometimes lead to confusion.

I've created a patch that will check for the first element it finds that is required and is invalid, and selects the correct tab, focusing it. I've tested this out and it seems to work well for the scenario.

Reproduce

To reproduce, you need to have a field inside a vertical tab that can fail validation. Usually, required and similarly validated fields are not inside tabsets in core

The easiest way to reproduce is apply 2911932-30-test-only.patch from #30, enable form_test (must have

$settings['extension_discovery_scan_tests'] = TRUE;

).

Then go to form-test/group-vertical-tabs and enter "bad" into the input in "Second group element", go to an different tab, then submit to trigger an error.
It not working === it does not switch to second tab, where the error is

Problem Happening
https://youtu.be/kYnLIIWCQes

Problem Fixed
https://youtu.be/Ydr06gybiFI

Note that this is specific to the Vertical Tabs render element provided by Drupal core. Any issues occurring in contrib elements, such as those provided by Field Group, will need to be filed as issues with the contirb module providing them.

Issue fork drupal-2911932

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr.les created an issue. See original summary.

mlncn’s picture

Status: Active » Needs review
mlncn’s picture

CKIDOW’s picture

+1

nod_’s picture

Status: Needs review » Needs work

Would have bet we had something for it already.

The patch is a little too specific. I would use something like

// get the errors on the page, return the form and the specific field that has an error.
const error = document.querySelectorAll(':invalid');
// get the vertical tab object this field is in
$(error[error.length -1]).closest('[data-vertical-tabs-panes]').data('verticalTab')
  .tabShow()

With the appropriate tests all around this to make sure the field is in a vertical tab.

Version: 8.3.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

EthanT’s picture

Original patch didn't grab the tab (was failing on the .length check). Modified a bit and is now working as expected.

EthanT’s picture

Status: Needs work » Needs review
EthanT’s picture

EthanT’s picture

Status: Needs review » Needs work

The last submitted patch, 10: vertical-tabs--focus-on-onvalid-7b.patch, failed testing. View results

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
hooroomoo’s picture

bnjmnm made their first commit to this issue’s fork.

klonos’s picture

I've tried to test this in latest D8.9.20 and D9.3.5, but did not see any change. Any vertical tab that is not the default/focused that has required fields does not get any focus whatsoever. Things are made worse by the fact that the default/native browser errors do not trigger any validation error summary at the top of the page, so it appears as though as clicking the submit button does nothing (when in fact the native validation error is triggered "in the background", but not shown because the vtab that contains the field is not the one that's focused).

bnjmnm’s picture

Version: 9.3.x-dev » 9.4.x-dev

bnjmnm’s picture

bnjmnm’s picture

Syntax error in drupalci.yml

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
6.08 KB

Fix + the test from #21 which should hopefully pass now.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bnjmnm’s picture

Priority: Normal » Major
Issue tags: +Accessibility, +JavaScript

Adding some tags to make this more popular

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

arnaud-brugnon’s picture

#22 can't be apply on Drupal 10

arnaud-brugnon’s picture

Status: Needs review » Needs work
arnaud-brugnon’s picture

Even if i improve #22, it does not work for Drupal 10 (I am not sure to even understand what does #22 suppose to do).

If someone want to unlock validation, i improve #7 for Drupal 10 and add support for textarea.

But i don't think it's the right direction to take.
It seems to specific (and it won't work if form element is not input, select or textarea).

Anyway, enjoy the improvement

arnaud-brugnon’s picture

FileSize
1.77 KB

By the way, here's the improvements for #22 if it can help.

But it's weird.
Most of the code was already in the core and like es6 support is gone, the patch is just about moving a behavior (which does not work at all)

bnjmnm’s picture

@arnaud-brugnon #22 provides intentionally failing tests that prove the problem exists and #24 gets those tests to pass, which proves the solution is effective. That should at least suggest the current solution is effective enough to not require a complete rewrite. Your patches completely remove the test coverage, which is not at all productive.

If someone want to unlock validation, i improve #7 for Drupal 10 and add support for textarea.

There's no need to target specific element types. There are selectors added via Drupal's Form API that can be targeted.

Patch #7 is a solution based on the assumption that Drupal uses HTML5 form validation. It would not work at all for server side validation as the logic is triggered on submit before any of that server side validation is run.

But it's weird.
Most of the code was already in the core and like es6 support is gone, the patch is just about moving a behavior

No.es6 files are no longer needed in Drupal 10 as the supported browsers all support modern syntax. Yes, this patch is about moving a behavior that successfully addressed an issue with CKEditor 5 - it's being moved so all Vertical tabs can benefit from the fix, not just those used in CKEditor 5 config, hence the @todo Remove when https://www.drupal.org/project/drupal/issues/2911932 lands. comment in the CKEditor5 JS.

(which does not work at all)

The test coverage provides objective proof that there was a problem and that patch #22 fixes it. Perhaps there are use cases that have not yet been accounted for, and details regarding how to reproduce those conditions would be helpful.

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

arnaud-brugnon’s picture

Okay.
Thanks for all the explanation.

arnaud-brugnon’s picture

#30 works like a charm

mgifford’s picture

Issue tags: +wcag211

WCAG tagging.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs steps to reproduce

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Let me know if I'm testing this wrong

Installed Drupal 10.1.x with a standard profile
Installed field_group module
In the article content type setup a tabs group with 2 tabs A and B.
Moved a required field into the B tab and a non required field into the A tab
Created an article not filling in the required field in tab B
When I click save tab B is displayed with the required field in red showing as required.

vija’s picture

I've deleted my comment as I figured out that my problem was problem with field_group tabs

crutch’s picture

Issue tags: -JavaScript +JavaScript

original

Thank you for explanation and information #38. I didn't realize field_group was the problem but it seems to be. This issue fixed it for us. Even though it results in resolving "Please fill out this field" errors first then core errors afterward, it should work fine.

bnjmnm’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce

re #37 testing should never require installing a contrib module like field_group. Any issue fixed in core should be reproduceable with just core, otherwise its an issue that should be filed with the contrib module. In this case it is a confirmed problem.

To reproduce, you need to have a field inside a vertical tab that can fail validation. Usually, required and similarly validated fields are not inside tabsets in core

The easiest way to reproduce IMO is apply 2911932-30-test-only.patch from #30, which already reproduces the problem for the purposes of testing. Enable theform_test module (must have

$settings['extension_discovery_scan_tests'] = TRUE;

).

Then go to form-test/group-vertical-tabs and enter "bad" into the input in "Second group element", go to an different tab, then submit to trigger an error.
It not working === it does not switch to second tab, where the error is

Problem Happening
https://youtu.be/kYnLIIWCQes

Problem Fixed
https://youtu.be/Ydr06gybiFI

Re #37

on 9.5.7 patches not applying. Both vertical and horizontal tabs have this issue. We won't be able to use tabs at this point in time.

That makes sense as patches are built for the most recent dev branch, which is currently 10.1.x. This can probably be made into a 9.x patch pretty easily - if you have success with that perhaps upload it here for users who may also need it.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the clarity @bnjmnm and the youtube links!

Did as you suggested and used the form_test module for testing.
Patch works great!

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

The last submitted patch, 30: 2911932-30-test-only.patch, failed testing. View results

lauriii’s picture

Version: 10.1.x-dev » 10.0.x-dev

Committed 8f9e0bd and pushed to 10.1.x. Thanks!

Triggered 10.0.x tests for backport.

  • lauriii committed 8f9e0bd0 on 10.1.x
    Issue #2911932 by bnjmnm, arnaud-brugnon, EthanT, leslie.cordell,...

  • lauriii committed 44e5b434 on 10.0.x
    Issue #2911932 by bnjmnm, arnaud-brugnon, EthanT, leslie.cordell,...
lauriii’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Needs work

Cherry-picked to 10.0.x. Still need a separate patch for 9.5.x backport.

Gauravvvv’s picture

Status: Needs work » Needs review
FileSize
6 KB

I have attached the re-rolled patch for 9.5.x

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reroll seems fine.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 49: 2911932-49.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Seems random

  • lauriii committed 5b7e07a2 on 9.5.x
    Issue #2911932 by bnjmnm, arnaud-brugnon, EthanT, leslie.cordell,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5b7e07a and pushed to 9.5.x. Thanks!

Status: Fixed » Closed (fixed)

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

sbrenner02’s picture

I'm using a module that makes the log message field in the 'information' tab of drupal core required ( https://www.drupal.org/project/require_revision_log_message ) and ran into this issue. Was hoping that this patch would address the issue but it does not seem to. If anyone has the capacity to assist that would be appreciated