Skip to content

Date Webform element fails validation #124

@ekes

Description

@ekes

This for sure effects when the Webform element is used in a composite, it might also be the case with other uses. So 'to reproduce' place a LocalGov Forms Date or Date of Birth element in a composite, and then place the composite on a form. It will always produce a validation error.

Reason

The base class has a preValidationCallback that sets the input value of the element including the DateTime object in the #value https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/WebformElement/DateBase.php?ref_type=heads#L511
This is not done for the inherited version of the WebformElement in LocalGov Forms because https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/WebformElement/DateBase.php?ref_type=heads#L500 $element['type'] is localgov_forms_date or localgov_forms_dob and they're not in the lookup array https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Plugin/WebformElement/DateBase.php?ref_type=heads#L490 (oh look it says it's a workaround*).

Putting the datetime object on the INPUT value on the form (not just the element value that is being passed around) is required because get the input https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Datetime/Element/Datelist.php?ref_type=heads#L294 and then looks for the object on it https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Datetime/Element/Datelist.php?ref_type=heads#L316 oh because core.

Solution

I'm going to think for a bit. But best I have at the moment is to implement the preValidationCallback on our class.


* RANT: Have I ever mentioned the way core date time element uses the date object for everything sucks: because seconds, because day without time, because of timezones, because it's stupid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions