Skip to content

UIComponent : date : showstime and validation : error "Please enter a valid date." #35330

@tales-desde-mileto

Description

@tales-desde-mileto

Preconditions (*)

  1. Magento 2.4.4
  2. Magento 2.4.3-p1

Steps to reproduce (*)

  1. Define a ui_component form.xml

  2. Add datetime UI component with: showsTime=true validation: validate-date=true

     <field name="prueba15_id">
         <argument name="data" xsi:type="array">
             <item name="config" xsi:type="array">
                   <item name="label" xsi:type="string" translate="true">Prueba15</item>
                   <item name="formElement" xsi:type="string">date</item>
                   <item name="dataType" xsi:type="string">date</item>
                   <item name="options" xsi:type="array">
                           <item name="showsTime" xsi:type="boolean">true</item>
                    </item>
                    <item name="validation" xsi:type="array">
                           <item name="validate-date" xsi:type="boolean">true</item>
                    </item>
             </item>
         </argument>
     </field>
    

Expected result (*)

  1. No error if date format is ok. But, always shows this error: "Please enter a valid date."

  2. I have tested with differents parameters in config and always same error: validate-datetime, pickerDateTimeFormat, etc

  3. I show that, perhaps, the problem is in this js function: Magento_Ui/js/form/element/date.js
    onShiftedValueChange: function (shiftedValue) {
    var value,
    formattedValue,
    momentValue;

    if (shiftedValue) {
    momentValue = moment(shiftedValue, this.pickerDateTimeFormat);

     if (this.options.showsTime && !this.options.timeOnly) {
         formattedValue = moment(momentValue).format(this.timezoneFormat);
         value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
     } else {
         value = momentValue.format(this.outputDateFormat);
     }
    

    } else {
    value = '';
    }

It gets the value on line:
value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();

But when it check it in validation,
rules.js:
'validate-date': [
function (value, params, additionalParams) {
var test = moment(value, additionalParams.dateFormat);

value is like: '2022-02-28T16:08:00.000Z'
And additionalParams.dateFormat is = 'M/DD/YYYY'
Then, always error.

Actual result (*)

  1. Always shows this error: "Please enter a valid date."

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • 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

Labels

Area: UI FrameworkIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: PR in progressReported on 2.4.4Indicates 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