Problem/Motivation
Constraint violations (and form validation errors ostensibly), are not able to target specific form elements within the smart date fieldset.

Steps to reproduce
- Create a custom constraint for a smart date field
- Cause the constraint to fire a validation violation on the 'value' element.
- When saving, see that the theme highlights all field elements with the red "error" border.
Proposed resolution
Implement errorElement() in SmartDateDefaultWidget.php()
Remaining tasks
Do the work
User interface changes
Errors allow targeting specific smart date field elements
API changes
n/a
Data model changes
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | smart_date-implement-errorelement-3385720-3.patch | 1.33 KB | coderdan |
| #3 | interdiff_2-3.txt | 803 bytes | coderdan |
| #2 | smart_date-implement-errorelement-3385720-1.patch | 1.35 KB | coderdan |
Issue fork smart_date-3385720
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
coderdan commentedComment #3
coderdan commentedThe patch in #2 prevents targeting elements outside of the time_wrapper sub-element, such as the 'make recurring' checkbox. This patch should solve for that by removing the time_wrapper as the sole parent for all elements.
Comment #4
skyriter commentedIn Drupal 11, this patch is throwing an error at runtime:
This might be related, though I am not sure:
- https://www.drupal.org/project/drupal/issues/3427739
I have run into the error on the VA site when trying to remove a paragraph item with a date and time from a field in the form.
Comment #5
skyriter commentedPer Dan, there's an update to this approach described here: https://www.drupal.org/node/3307919
I can confirm that this appears to work as expected.
Comment #7
mandclu commentedComment #9
mandclu commentedI was able to reproduce the issue using some of the validation built into Smart Date, though having the fix visible did require updating some of the validation code. As a result this should also serve as a good reference for anyone wanting their custom validation to also properly highlight the appropriate sub-form element.
Thanks for the work here, merged in.