AEM Forms 6.5: Manual Date Entry in HTML Forms Exports Incorrect Format to PDF

This article explains how to resolve issues with manual date entry in AEM Forms HTML forms exporting in an unexpected format to PDF, despite a configured data pattern.

Description description

Environment

Adobe Experience Manager (AEM) Forms 6.5 (JEE, Standalone, DEV and Production)

Issue/Symptoms

When a user manually enters a date value (e.g., M/D/YYYY, MM/DD/YY, or M/D/YY) into a date field in an HTML form, the exported PDF retains the manually entered format rather than converting it to the expected format (e.g., YYYY-MM-DD) as defined by the Data Pattern property in the AEM Forms Designer file.

  • The issue occurs only when the date is manually typed; using the date picker results in the correct format.
  • The field may visually reformat on tab-out in the HTML form, but the underlying value is not consistently updated.
  • When the form is submitted and the PDF is generated using the Output Service, the PDF may display the original, manually entered value.
  • This behavior is specific to manual date entry in HTML forms and does not affect date picker selection.

No specific error messages are logged for this issue.

Resolution resolution

  1. Add a Script to Normalize Manual Date Entry:

    • In the AEM Forms Designer, select the affected date field.

    • Add the following script to the field’s validation or exit event to normalize various manual date input formats:

      code language-none
      if (this.rawValue != null) {
                      var val = this.rawValue;
                      // Split input by "/"
                      var parts = val.split("/");
                      if (parts.length == 3) {
                          var month = parts[ 0] ;
                          var day = parts[ 1] ;
                          var year = parts[ 2] ;
                          // Pad month/day
                          if (month.length == 1) { month = "0" + month; }
                          if (day.length == 1) { day = "0" + day; }
                          // Convert 2-digit year to 4-digit
                          if (year.length == 2) { year = "20" + year; }
                          this.rawValue = year + "-" + month + "-" + day;
                      }
                  }
      
  2. Test the Form:

    • Preview the form in HTML and PDF modes.
    • Manually enter dates in various formats and verify that the exported PDF displays the date in the expected YYYY-MM-DD format.
  3. Deploy the Updated Form:

    • After confirming the fix, deploy the updated form to the relevant environment.

Cause

Manual date entry in HTML forms does not consistently trigger normalization to the configured data pattern, resulting in the original input format being exported to PDF. The provided script ensures all manual entries are reformatted to the expected pattern before export.

recommendation-more-help
experience-cloud-kcs-help-kbarticles