Skip to content

Commit f0baa28

Browse files
committed
Fix dob date validation on custom locale
1 parent 0c0393d commit f0baa28

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,16 @@ public function getHtmlId()
208208
*/
209209
public function getHtmlExtraParams()
210210
{
211+
$validators = [];
212+
$validators['required'] = true;
213+
$validators['validate-date'] = [
214+
'dateFormat' => $this->getDateFormat()
215+
];
216+
217+
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
218+
211219
$extraParams = [
212-
"'validate-date-au':true"
220+
"'validate-date':true",
213221
];
214222

215223
if ($this->isRequired()) {

lib/web/mage/validation.js

Lines changed: 5 additions & 5 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,13 +967,12 @@
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.')
975-
976976
],
977977
'validate-date-range': [
978978
function (v, elm) {

0 commit comments

Comments
 (0)