diff --git a/core.js b/core.js index 8d07cfe..62f2302 100644 --- a/core.js +++ b/core.js @@ -19,6 +19,7 @@ function Checkit(validations, options) { this.language = Checkit.i18n[options.language || Checkit.language] || {}; this.labelTransform = options.labelTransform || Checkit.labelTransform this.validations = prepValidations(validations || {}); + this.mode = options.mode; } Checkit.VERSION = '0.6.0'; @@ -198,7 +199,7 @@ function processItem(runner, currentValidation, key, context) { // If the rule isn't an existence / required check, return // true if the value doesn't exist. - if (rule !== 'accepted' && rule !== 'exists' && rule !== 'required') { + if (runner.checkit.mode !== 'strict' && rule !== 'accepted' && rule !== 'exists' && rule !== 'required') { if (value === '' || value == null) return; } var result = runRule(runner.validator, runner, rule, params) diff --git a/test/spec.js b/test/spec.js index 977ad13..5787cbb 100644 --- a/test/spec.js +++ b/test/spec.js @@ -453,4 +453,13 @@ describe('Checkit', function() { }); }); + describe('strict mode', function () { + it('should run all rules in strict mode', function(){ + var arr = Checkit({ + "emptyString": ['exactLength:1'] + }, {mode: 'strict'}).runSync({emptyString: ''}) + assert(arr[0] instanceof Checkit.Error) + }); + }); + });