@@ -238,7 +238,7 @@ Validatable.validatesUniquenessOf = getConfigurator('uniqueness', { async: true
238238/*!
239239 * Presence validator
240240 */
241- function validatePresence ( attr , conf , err ) {
241+ function validatePresence ( attr , conf , err , options ) {
242242 if ( blank ( this [ attr ] ) ) {
243243 err ( ) ;
244244 }
@@ -247,7 +247,7 @@ function validatePresence(attr, conf, err) {
247247/*!
248248 * Absence validator
249249 */
250- function validateAbsence ( attr , conf , err ) {
250+ function validateAbsence ( attr , conf , err , options ) {
251251 if ( ! blank ( this [ attr ] ) ) {
252252 err ( ) ;
253253 }
@@ -256,7 +256,7 @@ function validateAbsence(attr, conf, err) {
256256/*!
257257 * Length validator
258258 */
259- function validateLength ( attr , conf , err ) {
259+ function validateLength ( attr , conf , err , options ) {
260260 if ( nullCheck . call ( this , attr , conf , err ) ) return ;
261261
262262 var len = this [ attr ] . length ;
@@ -274,7 +274,7 @@ function validateLength(attr, conf, err) {
274274/*!
275275 * Numericality validator
276276 */
277- function validateNumericality ( attr , conf , err ) {
277+ function validateNumericality ( attr , conf , err , options ) {
278278 if ( nullCheck . call ( this , attr , conf , err ) ) return ;
279279
280280 if ( typeof this [ attr ] !== 'number' ) {
@@ -288,7 +288,7 @@ function validateNumericality(attr, conf, err) {
288288/*!
289289 * Inclusion validator
290290 */
291- function validateInclusion ( attr , conf , err ) {
291+ function validateInclusion ( attr , conf , err , options ) {
292292 if ( nullCheck . call ( this , attr , conf , err ) ) return ;
293293
294294 if ( ! ~ conf . in . indexOf ( this [ attr ] ) ) {
@@ -299,7 +299,7 @@ function validateInclusion(attr, conf, err) {
299299/*!
300300 * Exclusion validator
301301 */
302- function validateExclusion ( attr , conf , err ) {
302+ function validateExclusion ( attr , conf , err , options ) {
303303 if ( nullCheck . call ( this , attr , conf , err ) ) return ;
304304
305305 if ( ~ conf . in . indexOf ( this [ attr ] ) ) {
@@ -310,7 +310,7 @@ function validateExclusion(attr, conf, err) {
310310/*!
311311 * Format validator
312312 */
313- function validateFormat ( attr , conf , err ) {
313+ function validateFormat ( attr , conf , err , options ) {
314314 if ( nullCheck . call ( this , attr , conf , err ) ) return ;
315315
316316 if ( typeof this [ attr ] === 'string' ) {
@@ -325,14 +325,22 @@ function validateFormat(attr, conf, err) {
325325/*!
326326 * Custom validator
327327 */
328- function validateCustom ( attr , conf , err , done ) {
328+ function validateCustom ( attr , conf , err , options , done ) {
329+ if ( typeof options === 'function' ) {
330+ done = options ;
331+ options = { } ;
332+ }
329333 conf . customValidator . call ( this , err , done ) ;
330334}
331335
332336/*!
333337 * Uniqueness validator
334338 */
335- function validateUniqueness ( attr , conf , err , done ) {
339+ function validateUniqueness ( attr , conf , err , options , done ) {
340+ if ( typeof options === 'function' ) {
341+ done = options ;
342+ options = { } ;
343+ }
336344 if ( blank ( this [ attr ] ) ) {
337345 return process . nextTick ( done ) ;
338346 }
@@ -349,7 +357,7 @@ function validateUniqueness(attr, conf, err, done) {
349357
350358 var idName = this . constructor . definition . idName ( ) ;
351359 var isNewRecord = this . isNewRecord ( ) ;
352- this . constructor . find ( cond , function ( error , found ) {
360+ this . constructor . find ( cond , options , function ( error , found ) {
353361 if ( error ) {
354362 err ( error ) ;
355363 } else if ( found . length > 1 ) {
@@ -417,7 +425,8 @@ function getConfigurator(name, opts) {
417425 * @param {Function } callback called with (valid)
418426 * @returns {Boolean } True if no asynchronous validation is configured and all properties pass validation.
419427 */
420- Validatable . prototype . isValid = function ( callback , data ) {
428+ Validatable . prototype . isValid = function ( callback , data , options ) {
429+ options = options || { } ;
421430 var valid = true , inst = this , wait = 0 , async = false ;
422431 var validations = this . constructor . validations ;
423432
@@ -456,7 +465,7 @@ Validatable.prototype.isValid = function(callback, data) {
456465 async = true ;
457466 wait += 1 ;
458467 process . nextTick ( function ( ) {
459- validationFailed ( inst , attr , v , done ) ;
468+ validationFailed ( inst , attr , v , options , done ) ;
460469 } ) ;
461470 } else {
462471 if ( validationFailed ( inst , attr , v ) ) {
@@ -515,9 +524,14 @@ function cleanErrors(inst) {
515524 } ) ;
516525}
517526
518- function validationFailed ( inst , attr , conf , cb ) {
527+ function validationFailed ( inst , attr , conf , options , cb ) {
519528 var opts = conf . options || { } ;
520529
530+ if ( typeof options === 'function' ) {
531+ cb = options ;
532+ options = { } ;
533+ }
534+
521535 if ( typeof attr !== 'string' ) return false ;
522536
523537 // here we should check skip validation conditions (if, unless)
@@ -558,6 +572,7 @@ function validationFailed(inst, attr, conf, cb) {
558572 if ( kind !== false ) inst . errors . add ( attr , message , code ) ;
559573 fail = true ;
560574 } ) ;
575+ validatorArguments . push ( options ) ;
561576 if ( cb ) {
562577 validatorArguments . push ( function ( ) {
563578 cb ( fail ) ;
0 commit comments