From 601c44248c09fdf4db6659a0ec7ade94fa883ee0 Mon Sep 17 00:00:00 2001 From: Dmitry Fedyuk Date: Fri, 8 Sep 2017 20:35:05 +0300 Subject: [PATCH] 2.11.28 --- Ui/view/base/web/validator/cpf.js | 44 ++++++++++++++++--------------- composer.json | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Ui/view/base/web/validator/cpf.js b/Ui/view/base/web/validator/cpf.js index 58dc28d64..e4542854c 100644 --- a/Ui/view/base/web/validator/cpf.js +++ b/Ui/view/base/web/validator/cpf.js @@ -1,34 +1,36 @@ // 2017-07-12 // https://gist.github.com/cauerego/873308#file-jquery-validate-cpf-js -define(['df', 'Df_Ui/validator'], function(df, v) { +define(['df', 'df-lodash', 'Df_Ui/validator'], function(df, _, validator) { var f = function(v) { - v = v.replace(/\D/g,''); - /** @type {Boolean} */ var result = true; - /** @type {Number} */ var add = 0; - for (var i = 0; i < 9; i++) { - add += df.int(v.charAt(i)) * (10 - i); - } - var rev = 11 - (add % 11); - if (rev == 10 || rev == 11) { - rev = 0; - } - if (rev !== df.int(v.charAt(9))) { - result = false; - } - else { - add = 0; - for (i = 0; i < 10; i++) { - add += df.int(v.charAt(i)) * (11 - i); + v = _.trim(v); + /** @type {Boolean} */ var result = !/\D/.test(v); + if (result) { + /** @type {Number} */ var add = 0; + for (var i = 0; i < 9; i++) { + add += df.int(v.charAt(i)) * (10 - i); } - rev = 11 - (add % 11); + var rev = 11 - (add % 11); if (rev == 10 || rev == 11) { rev = 0; } - if (rev != df.int(v.charAt(10))) { + if (rev !== df.int(v.charAt(9))) { result = false; } + else { + add = 0; + for (i = 0; i < 10; i++) { + add += df.int(v.charAt(i)) * (11 - i); + } + rev = 11 - (add % 11); + if (rev == 10 || rev == 11) { + rev = 0; + } + if (rev != df.int(v.charAt(10))) { + result = false; + } + } } return result; }; - v.add('cpf', f, v.peav('CPF')); + validator.add('cpf', f, validator.peav('CPF')); }); \ No newline at end of file diff --git a/composer.json b/composer.json index 34a02cb8b..813a3c007 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "mage2pro/core" - ,"version": "2.11.27" + ,"version": "2.11.28" ,"description": "Mage2.PRO core package." ,"type": "magento2-module" ,"homepage": "https://mage2.pro"