From 19c20bbea77b10b50971f8db1898a2ee9815839f Mon Sep 17 00:00:00 2001 From: paulhbarker Date: Wed, 8 Sep 2021 13:08:23 -0600 Subject: [PATCH 1/2] update documentation for `sometimes` rule, fix bug where nested properties were not running any validation with the inclusion of the `sometimes` rule --- README.md | 12 ++++++++++++ dist/validator.js | 37 +++++++++++++++++++++++++++++-------- spec/sometimes-rule.js | 16 ++++++++++++++++ src/validator.js | 35 ++++++++++++++++++++++++++++------- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 898c0636..21581d25 100755 --- a/README.md +++ b/README.md @@ -303,6 +303,18 @@ The field under validation must be present and not empty only when any of the ot The field under validation must be present and not empty only when all of the other specified fields are not present. +#### sometimes + +In some situations, you may wish to run validation checks against a field only if that field is present in the data being validated. To quickly accomplish this, add the sometimes rule to your rule list: + +```js +let rules = { + email: 'sometimes|required|email' +} +``` + +In the example above, the email field will only be validated if it is present in the input. + #### same:attribute The given field must match the field under validation. diff --git a/dist/validator.js b/dist/validator.js index 250d12ca..3d559ef6 100644 --- a/dist/validator.js +++ b/dist/validator.js @@ -1,4 +1,4 @@ -/*! validatorjs - 2020-12-03 */ +/*! validatorjs - 2021-09-08 */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Validator = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i Date: Wed, 8 Sep 2021 13:11:38 -0600 Subject: [PATCH 2/2] update jsdoc for _suppliedWithData() --- src/validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validator.js b/src/validator.js index db93eeb7..517bb4e3 100755 --- a/src/validator.js +++ b/src/validator.js @@ -356,7 +356,7 @@ Validator.prototype = { /** * Determines if the attribute is supplied with the original data object. * - * @param {array} attribute + * @param {string} attribute * @return {boolean} */ _suppliedWithData: function (attribute) {