Comparing version 0.1.0 to 0.1.1
@@ -28,3 +28,3 @@ 'use strict'; | ||
}, | ||
message: function message(rule) { | ||
message: function message(value, field, rule) { | ||
return 'Please enter no more than ' + parseInt(rule.substr(3), 10) + ' characters.'; | ||
@@ -38,3 +38,3 @@ } | ||
}, | ||
message: function message(rule) { | ||
message: function message(value, field, rule) { | ||
return 'Please enter at least ' + parseInt(rule.substr(3), 10) + ' characters.'; | ||
@@ -52,13 +52,2 @@ } | ||
}, | ||
zipCode: { | ||
isInvalid: function isInvalid(value, field, rule, fields) { | ||
if (STANDARD_COUNTRIES.includes(fields.country.value)) { | ||
return validations.max.isInvalid(value, 'max10'); | ||
} | ||
return false; | ||
}, | ||
message: function message() { | ||
return validations.max.message('max10'); | ||
} | ||
}, | ||
email: { | ||
@@ -65,0 +54,0 @@ isInvalid: function isInvalid(value) { |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _promisePolyfill = require('promise-polyfill'); | ||
var _promisePolyfill2 = _interopRequireDefault(_promisePolyfill); | ||
var _validations = require('./validations'); | ||
@@ -22,2 +26,6 @@ | ||
if (!window.Promise) { | ||
window.Promise = _promisePolyfill2.default; | ||
} | ||
var Validator = function () { | ||
@@ -86,11 +94,11 @@ function Validator(fieldRules, form) { | ||
console.log(form); | ||
var fields = form || this.getFormState(); | ||
return new Promise(function (resolve) { | ||
return new _promisePolyfill2.default(function (resolve) { | ||
var rules = _this.fieldRules[field]; | ||
var errors = []; | ||
rules.forEach(function (rule) { | ||
var validationArguments = [fields[field].value, field, rule, fields, _this.additionalValidationParams]; | ||
var error = _this.getRule(rule); | ||
if (error.isInvalid(fields[field].value, field, rule, fields, _this.additionalValidationParams)) { | ||
errors.push(error.message(rule)); | ||
if (error.isInvalid.apply(error, validationArguments)) { | ||
errors.push(error.message.apply(error, validationArguments)); | ||
} | ||
@@ -116,3 +124,3 @@ }); | ||
} | ||
return Promise.all(promises).then(function (errors) { | ||
return _promisePolyfill2.default.all(promises).then(function (errors) { | ||
return errors.reduce(function (obj, error) { | ||
@@ -119,0 +127,0 @@ return _extends({}, obj, error); |
{ | ||
"name": "form-proof", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "This package provides basic form validations with 0 dependencies.", | ||
@@ -14,6 +14,3 @@ "main": "lib/", | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"**/src/*.{js,jsx}", | ||
"!**/examples/**" | ||
], | ||
"collectCoverageFrom": ["**/src/*.{js,jsx}", "!**/examples/**"], | ||
"coverageDirectory": "./coverage/", | ||
@@ -20,0 +17,0 @@ "collectCoverage": true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
233698
29
1344