Skip to content

Commit

Permalink
⏫ Forwardport of #11067 to 2.3-develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Jan 24, 2018
1 parent 8e77e2f commit 435a6c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 6 additions & 9 deletions app/code/Magento/Customer/Block/Widget/Dob.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,14 @@ public function getHtmlId()
*/
public function getHtmlExtraParams()
{
$extraParams = [
"'validate-date-au':true"
];

$validators = [];
if ($this->isRequired()) {
$extraParams[] = 'required:true';
$validators['required'] = true;
}

$extraParams = implode(', ', $extraParams);

return 'data-validate="{' . $extraParams . '}"';
$validators['validate-date'] = [
'dateFormat' => $this->getDateFormat()
];
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
}

/**
Expand Down
9 changes: 5 additions & 4 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,10 +967,10 @@
$.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.')

Expand Down

0 comments on commit 435a6c2

Please sign in to comment.