Skip to content

Missing validation message in custom date form field #38611

Open
@hiren-gujarati

Description

@hiren-gujarati

Preconditions and environment

  • Magento version: 2.4.6
  • Custom date field in any frontend form

Steps to reproduce

  1. Add custom date field with date button in frontend form.
  2. Open form which have custom date field.
  3. Try to submit blank form.
  4. All field show validation message as per there validation but date field not show any validation message

You can add custom date form field without calendar button using following code snippets,

<div class="field required">
    <label for="establishment_date" class="label">
        <span><?= /* @noEscape */ $block->escapeHtml(__('Establishment Date')) ?></span>
    </label>
    <div class="control">
        <input type="text"
                name="establishment_date"
                value=""
                title="<?= /* @noEscape */ $block->escapeHtml(__('Establishment Date')) ?>"
                class="input-text required-entry"
                id="establishment_date">
    </div>
</div>
<script type="text/javascript">
    require([
        'jquery',
        'mage/calendar'
    ], function ($) {
        $("#establishment_date").datepicker({
            dateFormat:'dd-mm-yy',
            changeYear: true,
            changeMonth: true,
        });
    });
</script>

Expected result

Date form field should show validation message same as other fields

image

Actual result

Date field not showing validation message without calendar button

image

Additional information

  • It is working fine when we add calendar button with date form field.

image

  • Date field validation is added after calendar button so, when we don't add button so, validation message is not showing. We can add button using following code snippet but it should work without button too.
<script type="text/javascript">
   require([
       'jquery',
       'mage/calendar'
   ], function ($) {
       $("#establishment_date").datepicker({
           dateFormat:'dd-mm-yy',
           changeYear: true,
           changeMonth: true,
           buttonText: '',
           showOn: 'both'
       });
   });
</script>

Error message is placed after button for date field from validation.js
https://github.com/magento/magento2/blob/2.4-develop/lib/web/mage/validation.js#L1880-L1883

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: UI FrameworkComponent: FrontendIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReported on 2.4.6Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions