-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions (*)
- Magento 2.4.4
- Magento 2.4.3-p1
Steps to reproduce (*)
-
Define a ui_component form.xml
-
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 (*)
-
No error if date format is ok. But, always shows this error: "Please enter a valid date."
-
I have tested with differents parameters in config and always same error: validate-datetime, pickerDateTimeFormat, etc
-
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 (*)
- 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”.