Problem/Motivation
When I have a validation error on some form elements, the following warning message is thrown:
Warning: Undefined array key "id" in uswds_base_preprocess_form_element() (line 17 of /app/docroot/themes/contrib/uswds_base/preprocess/element/form_element.preprocess.inc).
It doesn't seem to happen with text inputs, but does on textarea elements. I suspect it is also happening on other element types.
Looking at <uswds_base_preprocess_form_element it seems not all form elements have their id set at: $variables['element']['#attributes']['id']. It does seem that the id is always available at: $variables['element']['#id'] however.
Steps to reproduce
- Build or use a form with a textarea element.
- Trigger a server-side error on the textarea element, such as being
required. - A warning
Undefined array key "id" in uswds_base_preprocess_form_element()should be printed in the logs.
Proposed resolution
In uswds_base_preprocess_form_element conditionally check that the $variables['element']['#attributes']['id'] or $variables['element']['#id'] items exist before adding them to $variables['error_id'].
Remaining tasks
- Confirm bug and agree on solution.
- Create patch implementing solution.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screen Shot 2022-08-29 at 3.47.04 PM.png | 42.03 KB | pcate |
Issue fork uswds_base-3302483
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:
Comments
Comment #3
pcate commentedComment #4
pcate commentedComment #5
smustgrave commentedI tried testing this
Added a text(plain, long) field to a content type
Made the field required
Enabled uswds as the theme to use when creating content
Create a piece of content and NOT fill in the textarea. Click save
Didn't see any errors in logs
Comment #6
mferanda commentedComment #7
pcate commentedDid you see a Drupal error message on the page about the field being required after you saved? Also, just to confirm you are logging warnings not just errors?
Attached is a screenshot of the warning I'm seeing.
Comment #9
mferanda commentedLooks like a solid enough change... I'm good to include for RC2
Comment #10
mferanda commentedComment #11
mferanda commentedComment #12
mferanda commented