Problem/Motivation
While working on #3160238: Media Library widget produces "This value should not be null" error when field is required, we noticed that a fieldset containing an error, is not highlighted.
Steps to reproduce
Create a form, add a fieldset and in that fieldset, add a required field. Submit the form without values.
The fieldset is not marked as required.
Proposed resolution
When a fieldset contains an error, add an error class and mark the fieldset with a red border.
Remaining tasks
Decide if this should be provided specifally for the media library case, or a general approach is necessary.
User interface changes
A fieldset containing an error will be marked with a red border.
Comment | File | Size | Author |
---|---|---|---|
#12 | 3222368-nr-bot.txt | 149 bytes | needs-review-queue-bot |
Issue fork drupal-3222368
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 #2
JeroenTComment #3
amanire CreditAttribution: amanire at Environmental Defense Fund commentedThis is a good idea! I had to do this w/custom code on a project using the jQuery validation plugin. Without it, content contributors may become exasperated, having no idea which field in a submission is failing validation.
Comment #4
phenaproximaYeah, +1 for this. To be clear, I don't think that it's something that should automatically be applied to any fieldset which contains an error. But I think it's something that fieldsets should be able to opt into if needed.
Comment #5
JeroenTComment #8
JeroenTI added a red border for a fieldset containing errors in every theme.
About an option to opt-in, the error class is added in
\Drupal\Core\Render\Element\RenderElement::setAttributes()
, so I was thinking about an option '#skip_error_highlighting'.For fieldsets, we can set this by default to TRUE like this:
In setAttributes we can add an extra check if the option was set and equals true, then skip adding the error class.
For media_library, #3160238: Media Library widget produces "This value should not be null" error when field is required we can enable the option in MediaLibraryWidget. But I think we can fix that in a separate issue.
The solution abovemakes it possible to skip the error highlighting for every kind of form element. But I'm not sure if there really is a usecase for that.
Any thoughts?
Comment #12
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #13
Greg BoggsI gave this patch a test. For our use, this current patch is not sufficient because a required field must be visible on the screen or the error message does not display. Even with this patch, in a closed details element the message still not visible. So, you can't see the html5 error message about the field being required.