Problem/Motivation

If "required" validation on a field without a #title fails, we display an error region with no message.

Submitting as critical because we just silently fail on a form submission which can give the impression the submission was successful to the end user.

To reproduce the problem,

  1. Create or edit a view with a block display. For example, use "Who's online block".
  2. Add an exposed text filter. For example, add a filter on "Name (raw)".
  3. Make the field required.
  4. Do not supply a default value.
  5. Remove the Label.
  6. Under "Advanced", change "Use AJAX" to "Yes".
  7. Save the view.
  8. Enable the Contact module.
  9. Add the block with the exposed filter to the contact page (/contact/feedback by default).
  10. Visit the contact page.

When the page loads, even before you try to submit any form, you should see the empty error message.

Instead of using the Contact module, you could use a view with both page and block displays. Then add the block to the page created by the same view. There are alternative steps to reproduce in Comment #61.

The current behavior fails several WCAG requirements:

  1. (Level A): see Error Identification: Understanding SC 3.3.1
  2. (Level A): see Labels or Instructions
  3. (Level AA): see Error Instructions
  4. (Level AA): see Error Prevention (Legal, Financial, Data)
  5. (Level A): see Name, Role, Value

See Comments #62 and #64 for more information on these accessibility issues.

Proposed resolution

Display the ID of the form element as opposed to displaying nothing so it is clear that validation failed to developers (and end users - if developers don't find this bug in their own testing)

Remaining tasks

  • Accessibility review (notes in Comments #62 and #64 about how to assess this).
  • Decide on final wording. See discussion in Comment #61.

User interface changes

An error message now appears when validation fails:

validation message from patch in #41 for a field without title

or (with the inline_form_errors module enabled and the wording suggested in Comment #61)

validation message proposed in #61 for a field without title

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
#81 after_patch.png506.4 KBsmustgrave
#81 before_patch.png881.5 KBsmustgrave
#80 afterpatch-77.png37.6 KBasha nair
#80 beforePatc -77.png48.47 KBasha nair
#79 interdiff_77-79.txt1.31 KBravi.shankar
#79 2563173-79.patch4.73 KBravi.shankar
#77 interdiff-75_76.txt705 bytesabhijith s
#77 2563173-76.patch4.69 KBabhijith s
#76 2563173-75.patch4.69 KBabhijith s
#61 broken-form.png161.74 KBbenjifisher
#58 Screen Shot 2018-04-13 at 2.54.56 PM.png165.59 KBsean_e_dietrich
#56 interdiff.txt2.1 KBxano
#56 drupal_2563173_56.patch4.7 KBxano
#55 interdiff.txt833 bytesxano
#55 drupal_2563173_55.patch4.31 KBxano
#53 interdiff.txt2.13 KBankitjain28may
#53 validation-errors-2563173-53.patch3.48 KBankitjain28may
#51 drupal_2563173_51.patch3.52 KBxano
#44 2563173-44.png12.05 KBhgoto
#41 interdiff-2563173-35-41.txt3.04 KBhgoto
#41 2563173-41-test_only_should_fail.patch1.92 KBhgoto
#41 2563173-41.patch3.52 KBhgoto
#35 interdiff.txt1.74 KBstefan.r
#35 2563173-35.patch2.25 KBstefan.r
#30 interdiff.txt1.46 KBtim.plunkett
#30 2563173-formvalidator-30.patch1.66 KBtim.plunkett
#26 2563173-interdiff-20-26.txt1.68 KBlomo
#26 if_a_form_element_has-2563173-26.patch1.9 KBlomo
#22 if_a_form_element_has-2563173-20.patch1.48 KBnlisgo
#22 interdiff-2563173-16-20.txt648 bytesnlisgo
#16 if_a_form_element_has-2563173-16.patch866 bytesnlisgo
#16 interdiff-2563173-11-16.txt1.57 KBnlisgo
#11 2563173-11.patch1.3 KBDavid_Rothstein
#2 required.patch1.02 KBstefan.r
Capture d’écran 2015-09-04 à 13.57.29.png12.73 KBstefan.r

Comments

stefan.r created an issue. See original summary.

stefan.r’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB
cilefen’s picture

This does not meet the criteria for a critical bug.

stefan.r’s picture

If data from a webform is never submitted and the end user thinks it is how is that not data loss? :)

drupalove’s picture

I think form submission of data failing silently is critical. I can't believe this bug existed all this time.
Displaying the form ID which always exists and is descriptive despite it contains the hyphens I think is acceptable.

stefan.r’s picture

Yes, if we don't have a #title, the only things that are close to describing what the form element does are #id and #name... #id we can be sure that it's always set, and it certainly beats failing silently.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - looks great to me!

stefan.r’s picture

Title: If no #title is set, no error message is displayed when required validation fails » If no #title is set, form submission is lost when required validation fails
Issue summary: View changes

Thanks @Fabianx - clarifying the title.

David_Rothstein’s picture

Title: If no #title is set, form submission is lost when required validation fails » If a form element has no #title, required field validation displays insufficient warning to the user that the field failed validation
Version: 7.x-dev » 8.0.x-dev
Priority: Critical » Major
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

This actually affects Drupal 8 too - the impact is lessened there due to HTML5 validation, but I assume a decent number of people will want to turn off HTML5 validation on real sites anyway (since with current browsers it's pretty annoying).

I don't think this is critical really - there is still some visual indication that the form didn't submit (just really bad visual indication) and overall nothing breaks, it's just bad user experience. Plus as recommended in the code comment, you really shouldn't have a form element with no #title anyway...

The patch looks like an improvement, but it's adding a new translatable string for no reason (t('!name...') would work just as well as t('!id...')). And displaying the ID will have almost no meaning to end users here and will probably confuse them. If we're willing to add a new translatable string to fix this (which I think we are) then why not something like "The highlighted field is required", "A required field was not filled out", or similar?

stefan.r’s picture

In some cases there is _no_ visual indication/highlighting at all in D7. Which may be a separate bug, but it explains the criticalness there, and why "the highlighted field is required" wouldnt work.

The lack of highlighting where it's problematic and what makes this very hard to debug as there's actual data loss with webforms and such. I think we should keep the ID - it's usually indicative of the problematic field.

David_Rothstein’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

True, I guess for things like radios or checkboxes there might not be any visual indication currently.

Here's a patch for Drupal 8 to move this along. I would still lean towards something like "A required field was not filled out" myself, but this continues to use the ID in the message for now.

stefan.r’s picture

Issue tags: +Needs tests

Manually tested this and this works great! Can we add an automated test?

It's not just radios/checkboxes that were problematic, also some textfields from contrib modules. Not sure if it was custom styling or a separate bug but I've seen the lack of highlighting on several sites with search API exposed search fields.

Because of the lack of highlighting I think "A required field was not filled out" is problematic as we sometimes process various forms in the same request (in D7 at least, which may be a separate bug) and the "required" field may be in a different form altogether (e.g. the search box on top of the site when submitting a webform).

I agree outputting the ID is not very user-friendly, but this is an edge case (as #title will often be set) and if we don't point to the field we are leaving out some crucial information. Often people will still be able to tell which field we refer to based on the ID (especially developers, who will hopefully catch this error during testing/development)

Status: Needs review » Needs work

The last submitted patch, 11: 2563173-11.patch, failed testing.

The last submitted patch, 11: 2563173-11.patch, failed testing.

nlisgo’s picture

Assigned: Unassigned » nlisgo

I will take on the task of adding test coverage for this.

nlisgo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.57 KB
new866 bytes

#id is also not mandatory and we need to check that it is set before we try to use it. This patch addresses this but if the aim of this issue is to ensure that an error message is sent it might be better to use a generic error message such as 'Field is required.'

stefan.r’s picture

Status: Needs review » Needs work

I'm pretty sure #id is always set by the time this code is executed, see FormBuilder::doBuildForm():

      $unprocessed_id = 'edit-' . implode('-', $element['#parents']);
      $element['#id'] = Html::getUniqueId($unprocessed_id);
stefan.r’s picture

I disagree about a "Field is required." message being sufficient.

The required form element may be in a completely different part of the page and not highlighted, and too hard to identify when we merely hint at "some" field being required without pointing out which one.

It's also not a very useful message to post to an issue queue or to Google for as a developer/site builder. We shouldn't have to force them into using a debugger.

We're catering to an edge case (#title not being set). In most cases, #title will be set and we'll just use that.

nlisgo’s picture

@stefan.r I did some debugging around the failing test in #11 to determine what the #id was for the field and there was no #id set. I will investigate some more around the code that you mentioned in #17.

stefan.r’s picture

Hmm in D7 the only way to reach the form validation was right after building the form in drupal_process_form().

The D8 equivalent is FormBuilder::processForm(), which within core seems to be the only place calling FormValidator::validateForm(), and the core.api.php docs state "Forms are defined as classes that implement the \Drupal\Core\Form\FormInterface and are built using the \Drupal\Core\Form\FormBuilder class."

So it seems we can be reasonably sure that on a form array the #id will always be set and the unit test itself was "wrong". That said, it can't hurt to leave the else statement there just in case someone does somehow pass in a form that wasn't built using the form builder (and in such case a "Field is required" might actually be appropriate as we don't even have a ID to display).

stefan.r’s picture

So the current patch may be fine, leaving CNW as this could still use a test that asserts for the ID error message.

nlisgo’s picture

Assigned: nlisgo » Unassigned
Status: Needs work » Needs review
StatusFileSize
new648 bytes
new1.48 KB

formBuilder does not seem to be triggered in Drupal\Tests\Core\Form\FormValidatorTest::testRequiredErrorMessage()

The form is manually prepared and passed directly to the FormValidator.

Given that a form element can be passed to a validator without the #id being set then I still think we should check that it exists before attempting to display it.

I've added a test case where the #id is set.

stefan.r’s picture

Issue tags: -Needs tests

Yeah that sounds right, it's not triggered because it's a unit test but we don't document anywhere that #id must be set (nor do we fail when it isn't), or that $form must have been built using the FormBuilder.

Patch looks good, unit test passes locally so RTBC for me. Leaving at NR for someone else to have a look at this as I had written the original patch.

drupalove’s picture

Thanks guys for your effort.
Can I suggest we have two short comments similar to:
// Identify the required form element by its title.
and
// Otherwise, identify the required form element by its ID.

drupalove’s picture

Even more accurate:
Include the element title in the error message.
and
Otherwise, display the element ID in the error message.

lomo’s picture

This is a pretty nasty bug, so I'd like to see this get fixed. My only change here was to add the comments suggested in #24/#25.

I think this is RTBC-able, but since I made *any* kind of patch, I probably should not be the one to set that status. ;-)

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - looks great to me.

stefan.r’s picture

Thanks @Fabianx! RTBC++

catch’s picture

Issue tags: +rc target triage
tim.plunkett’s picture

StatusFileSize
new1.66 KB
new1.46 KB

Just tweaking the comments. Looks like a reasonable change to FormValidator.

tim.plunkett’s picture

Title: If a form element has no #title, required field validation displays insufficient warning to the user that the field failed validation » Display 'required' validation errors for form elements that do not provide a #title
stefan.r’s picture

Thanks!

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -rc target triage

Looking at the "after" screenshot up there, that definitely isn't going to fly. There is no way for a content author to understand what field that is when we're exposing HTML ID details that would only be visible to them in view source.

The core committers talked about this on our triage call, and while the bug would be great to fix, this isn't a regression from D7 (it's rather an existing bug in D7), so not something we need to prioritize during RC (we could just as easily fix this in a patch/minor release). Additionally, we need to solve it a different way (e.g. making #title required for #required fields, or having a known label property to get some kind of human-readable string).

Un-marking RC target and needs working.

stefan.r’s picture

This is not just affecting content authors, it also affects end users submitting any kind of form.

In Drupal 7 this issue is critical IMO so it would be good if we could get this into 8.0.1.

Let's change the message to "A required field was not filled out" as suggested by David_Rothstein.

The ID is still useful debugging information, so that could be in a trigger_error (in addition to the regular message) so that it only displays on development sites (and so that it's logged). Production sites are assumed to have error display turned off, and if they are turned on against our advice, content authors may end up seeing error messages far more obscure than something containing a HTML ID anyway.

stefan.r’s picture

Status: Needs work » Needs review
StatusFileSize
new2.25 KB
new1.74 KB

Status: Needs review » Needs work

The last submitted patch, 35: 2563173-35.patch, failed testing.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Form/FormValidator.php
    @@ -296,8 +297,16 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
    +        // If no title is set, display the element ID in the error message.
    +        elseif (isset($elements['#id'])) {
    +          $form_state->setError($elements, $this->t('A required field was not filled out.'));
    ...
             else {
               $form_state->setError($elements);
             }
    

    We're not actually displaying the element ID any more, so why not just improve the else case?

  2. +++ b/core/lib/Drupal/Core/Form/FormValidator.php
    @@ -296,8 +297,16 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
    +          // Log the field ID for debugging purposes. We implement this as a
    +          // trigger_error() as the ID may not be understandable to end users.
    +          trigger_error((string) new FormattableMarkup('@name field is required.', array('@name' => $elements['#id'])));
    

    Why do we need this here? Also if we add it, it should be tested.

stefan.r’s picture

1 makes sense! As to 2, I believe a trigger_error() is useful for site builder debugging purposes, as the required field is not always immediately visible.

stefan.r’s picture

Issue tags: +Novice

Bumping this and marking as novice, as I just ran into this issue again (where a webform submission would silently fail without any error message due to a required search field elsewhere on the page).

stefan.r’s picture

Version: 8.0.x-dev » 8.1.x-dev
hgoto’s picture

Status: Needs work » Needs review
StatusFileSize
new3.52 KB
new1.92 KB
new3.04 KB

I revised the patch #35.

1. Fixed the point 1 in comment #37.

        // If no title is set, display a vague error message.
        else {
          $form_state->setError($elements, $this->t('A required field was not filled out.'));
          // Log the field ID for debugging purposes. We implement this as a
          // trigger_error() as the ID may not be understandable to end users.
          if (isset($elements['#id'])) {
            trigger_error((string) new FormattableMarkup('@name field is required.', array('@name' => $elements['#id'])));
          }
        }

2. Added a test to test the trigger_error().

            trigger_error((string) new FormattableMarkup('@name field is required.', array('@name' => $elements['#id'])));

The test case became long to test the trigger_error()...

    // If no title is set and id is set, a PHP error is raised.
    if (!isset($element['#title']) && !isset($element['#required_error']) &&
      isset($element['#id'])) {
      // Change the PHP error handler temporarily for test.
      $error_checker = $this->getMockBuilder('stdClass')
        ->setMethods(array('tempErrorHandler'))
        ->getMock();
      $error_checker->expects($this->once())
        ->method('tempErrorHandler');
      set_error_handler(array($error_checker, 'tempErrorHandler'));

      $form_validator->validateForm('test_form_id', $form, $form_state);

      // Reset the PHP error handler.
      restore_error_handler();
    }
    else {
      $form_validator->validateForm('test_form_id', $form, $form_state);
    }

This test for trigger_error() may be unnecessary...

Anyway, I'd like this to be reviewed. Thank you.

Status: Needs review » Needs work

The last submitted patch, 41: 2563173-41-test_only_should_fail.patch, failed testing.

stefan.r’s picture

Status: Needs work » Needs review
Issue tags: -Novice

Patch and test look good, and feedback from #33 and #37 has been addressed.

Can we update the screenshot in the issue summary?

hgoto’s picture

Issue summary: View changes
StatusFileSize
new12.05 KB

I updated the screenshot in the summary as stefan.r told.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

djdevin’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue tags: +Triaged for D8 major current state

I reproduced this in 8.4.x-dev. Patches address the issue and still apply to 8.4.x-dev.

xjm’s picture

Issue tags: +Triaged core major

Thanks @djdevin for evaluating the issue and confirming it's still valid! @catch, @cilefen, @alexpott, @Cottser, @lauriii, and I discussed and agreed this issue is indeed a major bug due to the broad usability impact of the silent failure.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xano’s picture

StatusFileSize
new3.52 KB

Re-roll for 8.6.x.

Status: Needs review » Needs work

The last submitted patch, 51: drupal_2563173_51.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ankitjain28may’s picture

Status: Needs work » Needs review
StatusFileSize
new3.48 KB
new2.13 KB

The above patch contains some coding standard errors.

Status: Needs review » Needs work

The last submitted patch, 53: validation-errors-2563173-53.patch, failed testing. View results

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new4.31 KB
new833 bytes

This fixes the test failure.

Can we instead trigger the error when the form is built? It'll likely expose more problems with core we'll need to fix in this issue, but the errors will show up less randomly, and earlier on (fail fast). Nah, when forms are built we can't easily figure out which elements will need a title in the end.

xano’s picture

StatusFileSize
new4.7 KB
new2.1 KB

I added some more details to the error message, explaining this new log entry site administrators will be seeing. It links to the change record I just wrote, which includes several code examples.

sean_e_dietrich’s picture

Working on this as part of DrupalCon Nashville!

sean_e_dietrich’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new165.59 KB

I've been able to confirm that this patch works.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs usability review
  1. +++ b/core/lib/Drupal/Core/Form/FormValidator.php
    @@ -297,10 +298,19 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
    +          $form_state->setError($elements, $this->t('A required field was not filled out.'));
    

    As users might see this message I think we need a usability review here. To me the current text is a little odd. It implies the field needs to be a be "filled out" but potentially this could be a tickbox or select box. I think also the present tense is better and matches the error when there is a title. I'd suggest A required field is empty.

  2. +++ b/core/lib/Drupal/Core/Form/FormValidator.php
    @@ -297,10 +298,19 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
    +            trigger_error((string) new FormattableMarkup('@name field is required, but because it has no #title, users cannot be shown exactly which element this is. See the documentation at https://www.drupal.org/node/2956364 for which changes must be made to the code.', [
    +              '@name' => $elements['#id'],
    +            ]));
    

    Why not just log an error using the log system?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

benjifisher’s picture

Issue tags: -Needs usability review +Needs issue summary update
StatusFileSize
new161.74 KB

Usability review

We discussed this at the Usability Meeting today (2018-12-18): https://www.youtube.com/watch?v=9GIdotOoVy8.

Almost any text that we use will be an improvement over the current state, so thanks for working on this.

Notice that the text will be repeated below each affected field if the inline_form_errors module is enabled: see the screenshot below. That means we should try to choose text that will work both at the top of the form and also repeated beneath the empty forms.

We like the suggestion in #59 better than the current patch, but we are not sure that "empty" is a good user-facing word to use. Both suggest that there is only one empty form field, when there might be more than one. Variants that allow for multiple empty fields tend to be awkward and longer than we like.

It would also be a good idea to tell the user how to fix the problem instead of describing the problem.

How about "Please enter something for each required field."? This works fairly well both at the top of the form and beneath each empty field. It tells the user how to fix the problem. It works fairly well whether there is a single empty field or several.

Here is a screenshot of the Umami theme with a custom form and my suggested text, with the inline_form_errors module enabled. (I used the browser tools to insert the recommended text.) My test form does not have titles for the input elements, but it does have descriptions: that is where the text "This input element is required and it does have a #title key." and "Same problem here!" comes from.

screenshot showing errors for two required text fields that have been left empty

Other points

I am adding the "Needs issue summary update" tag because the summary does not explain how to reproduce the problem. I did the following:

  • Install the Disable HTML5 validation module.
  • Create a custom form with a required field that does not have a title.
  • Test with and without the inline_form_errors module.
andrewmacpherson’s picture

Issue summary: View changes
Issue tags: +Accessibility, +Needs accessibility review

I spotted this being discussed in the #UX Slack channel. I haven't read the whole issue yet, just tagging for accessibility review.

It's a WCAG failure at level A, for sure See Error Identification: Understanding SC 3.3.1.

To satisfy that WCAG success criterion, we must inform the user which input failed validation, ideally using text. In the case of FAPI elements without a #title, that's awkward because we can't use the name of the element in the message the user sees. Nonetheless, I think this can still pass WCAG "Error Identification", but it would be good to assess it carefully for all the techniques documented in WCAG.

Test with and without the inline_form_errors module

Yes, that's very important. Some of the documented WCAG techniques may only apply when IFE is enabled.

It would also be a good idea to tell the user how to fix the problem instead of describing the problem.

Yes that's covered by some other WCAG success criteria. Basically all the SCs in the guideline group "Input Assistance" applies here:

  • Labels or Instructions (level A). In the case of compund fields or filters, this might be satisfied by fieldset legends, but it needs a detailed look at the situations.
  • Error Suggestions (level AA). Definitely relevant. It's important to know how to reach a successful submission.
  • Error Prevention (Legal, Financial, Data) (level AA) - relates to accidental data loss/change. Probably not relevant to listing filters, but worth considering other possible situations on config/content forms.

Aside, how many FAPI elements lack a #title? The wider problem is avoiding that situation entirely. I think there may be a related issue sonewhere.

benjifisher’s picture

Aside, how many FAPI elements lack a #title? The wider problem is avoiding that situation entirely. I think there may be a related issue sonewhere.

It is certainly good practice to supply a #title element, and this issue is all about doing the best we can when people violate that standard. For example, here is what I used to test:

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['enter_text_or_else'] = [
      '#type' => 'textfield',
      // '#title' => $this->t('Enter text or else!'),
      '#description' => $this->t('This input element is required and it has no #title key.'),
      '#maxlength' => 64,
      '#required' => TRUE,
      '#size' => 64,
      '#weight' => '0',
    ];
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    ];

    return $form;
  }

Is there an issue somewhere to make #title required?

To satisfy that WCAG success criterion, we must inform the user which input failed validation, ideally using text.

The FAPI does set name="enter_text_or_else" (in my example). So I think we can use a link to #enter_text_or_else (or whatever the key is in the form array). I think that @JacobRockowitz mentioned (during the Usability meeting) that the Webform module already does that. Maybe we could borrow some of his code.

andrewmacpherson’s picture

I found the related issue about ensuring all FAPI elements have a #title.

Another WCAG success criterion, which I missed in #62, is "Name, Role, Value" (level A). It says all form inputs must have a programmatically-determinable accessible name. This is more strict than "tell the user how to fix the problem" - they still need to know what an input is called. The approach suggested here means we could satisfy the WCAG "Error Identification" and "Error suggestion" criteria, yet still fail "Name, Role, Value". The screenshot in #61 is an example of this - the user is aware of exactly which two inputs have errors, and that they must provide a value for both, but can't tell what each one is for.

I think it's still worth pursuing the related issue, and making FAPI #title mandatory, because it's the most reliable way to satisfy WCAG 4.1.2 "Name, Role, Value". The accessible name doesn't necessarily have to come via the FAPI #title - it could come from an aria-labelledby in #attributes, or a <label> created by a Twig template. But if #title isn't there, then this is a gap that module developers must fill by another means. A mandatory #title is way more robust for FAPI to ensure an associated label <label>, and wouldn't prevent themers taking different approach with aria attributes.

This is a tricky issue. On the one hand, it's worth doing because it adds a level of robustness for "Error Identification" in an unusual circumstance. Yet it still leaves a hole for "Name, Role, Value" and "Labels and Instructions", so I think ensuring a #title is the more important issue to tackle.

benjifisher’s picture

@gbirch and I worked on the steps to reproduce this issue at the ContributionWeekend2019 (Boston).

I am adding more explicit steps to reproduce, and I am summarizing Comments #62 and #64 in the issue summary.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

savage1974’s picture

Thanks Xano. Your patch works on my drupal 9.1.8

best regards,

Savage

savage1974’s picture

Hi, all.
Drupal 9.1.10 - Could not apply patch #56

best regards,

Savage

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.

xjm’s picture

Issue tags: -Triaged for D8 major current state
abhijith s’s picture

StatusFileSize
new4.69 KB

Rerolled patch #56 for 9.5.x.

abhijith s’s picture

StatusFileSize
new4.69 KB
new705 bytes

Fixing the custom command failed issue

Status: Needs review » Needs work

The last submitted patch, 77: 2563173-76.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.73 KB
new1.31 KB

Trying to fix failed tests of patch #79.

asha nair’s picture

StatusFileSize
new48.47 KB
new37.6 KB

Applied patch in #77 in 9.5.x-dev. Adding results as screenshots

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2568889: Views exposed text filter set to required shows an empty error and form error on page load
StatusFileSize
new881.5 KB
new506.4 KB

Tested the patch in #79

Confirmed the issue without the patch
Confirmed the patch fixed the issue.

Going to mark as reviewed but fyi there's https://www.drupal.org/project/drupal/issues/2568889#comment-14606806 to prevent the error from appearing all together because nothing was submitted.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

There are two uncompleted tasks in the Issue Summary. Setting back to NW for those items.

This is tagged for an accessibility review and that has not happened. Can someone here take that on?

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.

mgifford’s picture

Issue tags: +wcag331

Tagging for WCAG 3.3.1.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

kentr’s picture

Issue tags: -Needs backport to D7

#933004: Test that all form elements have a #title for accessibility needs review, and I think it will fix the problem in this issue.

Sounds like @andrewmacpherson also suggested that it will in #64.

I don't think this needs backport to D7 anymore.