Problem/Motivation

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

Screenshot of errors

Steps to reproduce

  1. Create a custom constraint for a smart date field
  2. Cause the constraint to fire a validation violation on the 'value' element.
  3. 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

Issue fork smart_date-3385720

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:

Comments

coderdan created an issue. See original summary.

coderdan’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB
coderdan’s picture

The 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.

skyriter’s picture

In Drupal 11, this patch is throwing an error at runtime:

TypeError: Drupal\\Component\\Utility\\NestedArray::getValue(): 
Argument #2 ($parents) must be of type array, null given, 
called in /var/lib/tugboat/docroot/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateDefaultWidget.php on line 149 
in Drupal\\Component\\Utility\\NestedArray::getValue() (line 69 of core/lib/Drupal/Component/Utility/NestedArray.php)

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.

skyriter’s picture

Per 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.

mandclu’s picture

Version: 4.1.x-dev » 4.3.x-dev

  • mandclu committed af7a6f93 on 4.3.x authored by skyriter
    task: #3385720 Implement errorElement() in Widgets
    
    By: coderdan
    By:...
mandclu’s picture

Status: Needs review » Fixed

I 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.