Skip to content

Commit 435a6c2

Browse files
committed
⏫ Forwardport of #11067 to 2.3-develop branch
1 parent 8e77e2f commit 435a6c2

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,14 @@ public function getHtmlId()
208208
*/
209209
public function getHtmlExtraParams()
210210
{
211-
$extraParams = [
212-
"'validate-date-au':true"
213-
];
214-
211+
$validators = [];
215212
if ($this->isRequired()) {
216-
$extraParams[] = 'required:true';
213+
$validators['required'] = true;
217214
}
218-
219-
$extraParams = implode(', ', $extraParams);
220-
221-
return 'data-validate="{' . $extraParams . '}"';
215+
$validators['validate-date'] = [
216+
'dateFormat' => $this->getDateFormat()
217+
];
218+
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
222219
}
223220

224221
/**

lib/web/mage/validation.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
if (typeof define === 'function' && define.amd) {
1010
define([
1111
'jquery',
12+
'moment',
1213
'jquery/ui',
1314
'jquery/validate',
1415
'mage/translate'
1516
], factory);
1617
} else {
1718
factory(jQuery);
1819
}
19-
}(function ($) {
20+
}(function ($, moment) {
2021
'use strict';
2122

2223
var creditCartTypes, rules, showLabel, originValidateDelegate;
@@ -966,10 +967,10 @@
966967
$.mage.__('Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.') //eslint-disable-line max-len
967968
],
968969
'validate-date': [
969-
function (v) {
970-
var test = new Date(v);
970+
function (value, params, additionalParams) {
971+
var test = moment(value, additionalParams.dateFormat);
971972

972-
return $.mage.isEmptyNoTrim(v) || !isNaN(test);
973+
return $.mage.isEmptyNoTrim(value) || test.isValid();
973974
},
974975
$.mage.__('Please enter a valid date.')
975976

0 commit comments

Comments
 (0)