@@ -184,55 +184,61 @@ Validator.prototype._checkWrapper = function(rules, isMultipleRules) {
184
184
}
185
185
186
186
// Check required fields
187
- if ( ( value === undefined || value === null ) && check . type !== "forbidden" ) {
188
- if ( schema . optional !== true && ! Array . isArray ( schema ) ) {
187
+ if ( ( value === undefined || value === null ) ) {
188
+ if ( check . type === "forbidden" )
189
+ continue ;
190
+
191
+ if ( schema . optional === true )
192
+ continue ;
193
+
194
+ if ( ! Array . isArray ( schema ) ) {
189
195
self . handleResult ( errors , stack , self . makeError ( "required" ) ) ;
190
- } else
191
196
continue ;
197
+ }
192
198
193
- } else {
194
- // Call the checker function
195
- if ( check . iterate ) {
196
- let errorInCurrentArray = false ;
197
- const l = value . length ;
198
- for ( let i = 0 ; i < l ; i ++ ) {
199
- let _stack = stack + "[" + i + "]" ;
200
- let res = check . fn . call ( self , value [ i ] , schema , _stack , obj ) ;
201
- if ( res !== true ) {
202
- errorInCurrentArray = true ;
203
- self . handleResult ( errors , _stack , res ) ;
204
- }
199
+ } // else {
200
+ // Call the checker function
201
+ if ( check . iterate ) {
202
+ let errorInCurrentArray = false ;
203
+ const l = value . length ;
204
+ for ( let i = 0 ; i < l ; i ++ ) {
205
+ let _stack = stack + "[" + i + "]" ;
206
+ let res = check . fn . call ( self , value [ i ] , schema , _stack , obj ) ;
207
+ if ( res !== true ) {
208
+ errorInCurrentArray = true ;
209
+ self . handleResult ( errors , _stack , res ) ;
205
210
}
206
- /**
211
+ }
212
+ /**
207
213
* If this is second part of a multiRule array check and the array
208
214
* is valid, then the rule is valid.
209
215
*/
210
- if ( ! errorInCurrentArray && isMultipleRules && check . secondPart ) {
211
- return true ;
212
- }
213
- } else {
214
- let res = check . fn . call ( self , value , schema , stack , obj ) ;
216
+ if ( ! errorInCurrentArray && isMultipleRules && check . secondPart ) {
217
+ return true ;
218
+ }
219
+ } else {
220
+ let res = check . fn . call ( self , value , schema , stack , obj ) ;
215
221
216
- if ( isMultipleRules ) {
217
- if ( res === true ) {
218
- /**
222
+ if ( isMultipleRules ) {
223
+ if ( res === true ) {
224
+ /**
219
225
* Object and array checks are divided into two internal checks. In case of a multiRule
220
226
* we have to make sure to check both parts. Thus we we continue to also do the second
221
227
* check if their is one.
222
228
*/
223
- const nextRule = rules [ i + 1 ] ;
224
- if ( nextRule && nextRule . secondPart ) {
225
- continue ;
226
- }
227
- // Jump out after first success and clear previous errors
228
- return true ;
229
+ const nextRule = rules [ i + 1 ] ;
230
+ if ( nextRule && nextRule . secondPart ) {
231
+ continue ;
229
232
}
233
+ // Jump out after first success and clear previous errors
234
+ return true ;
230
235
}
231
-
232
- if ( res !== true )
233
- self . handleResult ( errors , stack , res ) ;
234
236
}
237
+
238
+ if ( res !== true )
239
+ self . handleResult ( errors , stack , res ) ;
235
240
}
241
+ //}
236
242
}
237
243
238
244
return errors . length === 0 ? true : errors ;
0 commit comments