Skip to content

Commit

Permalink
Fix dob date validation on custom locale
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimVT committed Sep 26, 2017
1 parent 0c0393d commit f0baa28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/code/Magento/Customer/Block/Widget/Dob.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,16 @@ public function getHtmlId()
*/
public function getHtmlExtraParams()
{
$validators = [];
$validators['required'] = true;
$validators['validate-date'] = [
'dateFormat' => $this->getDateFormat()
];

return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';

$extraParams = [
"'validate-date-au':true"
"'validate-date':true",
];

if ($this->isRequired()) {
Expand Down
10 changes: 5 additions & 5 deletions lib/web/mage/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
if (typeof define === 'function' && define.amd) {
define([
'jquery',
'moment',
'jquery/ui',
'jquery/validate',
'mage/translate'
], factory);
} else {
factory(jQuery);
}
}(function ($) {
}(function ($, moment) {
'use strict';

var creditCartTypes, rules, showLabel, originValidateDelegate;
Expand Down Expand Up @@ -966,13 +967,12 @@
$.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
],
'validate-date': [
function (v) {
var test = new Date(v);
function (value, params, additionalParams) {
var test = moment(value, additionalParams.dateFormat);

return $.mage.isEmptyNoTrim(v) || !isNaN(test);
return $.mage.isEmptyNoTrim(value) || test.isValid();
},
$.mage.__('Please enter a valid date.')

],
'validate-date-range': [
function (v, elm) {
Expand Down

0 comments on commit f0baa28

Please sign in to comment.