@ -8,7 +8,7 @@
* http : //ReactiveRaven.github.com/jqBootstrapValidation/
* http : //ReactiveRaven.github.com/jqBootstrapValidation/
* /
* /
( function ( $ ) {
( function ( $ ) {
var createdElements = [ ] ;
var createdElements = [ ] ;
@ -23,13 +23,13 @@
autoAdd : {
autoAdd : {
helpBlocks : true
helpBlocks : true
} ,
} ,
filter : function ( ) {
filter : function ( ) {
// return $(this).is(":visible"); // only validate elements you can see
// return $(this).is(":visible"); // only validate elements you can see
return true ; // validate everything
return true ; // validate everything
}
}
} ,
} ,
methods : {
methods : {
init : function ( options ) {
init : function ( options ) {
var settings = $ . extend ( true , { } , defaults ) ;
var settings = $ . extend ( true , { } , defaults ) ;
@ -38,18 +38,18 @@
var $siblingElements = this ;
var $siblingElements = this ;
var uniqueForms = $ . unique (
var uniqueForms = $ . unique (
$siblingElements . map ( function ( ) {
$siblingElements . map ( function ( ) {
return $ ( this ) . parents ( "form" ) [ 0 ] ;
return $ ( this ) . parents ( "form" ) [ 0 ] ;
} ) . toArray ( )
} ) . toArray ( )
) ;
) ;
$ ( uniqueForms ) . bind ( "submit" , function ( e ) {
$ ( uniqueForms ) . bind ( "submit" , function ( e ) {
var $form = $ ( this ) ;
var $form = $ ( this ) ;
var warningsFound = 0 ;
var warningsFound = 0 ;
var $inputs = $form . find ( "input,textarea,select" ) . not ( "[type=submit],[type=image]" ) . filter ( settings . options . filter ) ;
var $inputs = $form . find ( "input,textarea,select" ) . not ( "[type=submit],[type=image]" ) . filter ( settings . options . filter ) ;
$inputs . trigger ( "submit.validation" ) . trigger ( "validationLostFocus.validation" ) ;
$inputs . trigger ( "submit.validation" ) . trigger ( "validationLostFocus.validation" ) ;
$inputs . each ( function ( i , el ) {
$inputs . each ( function ( i , el ) {
var $this = $ ( el ) ,
var $this = $ ( el ) ,
$controlGroup = $this . parents ( ".form-group" ) . first ( ) ;
$controlGroup = $this . parents ( ".form-group" ) . first ( ) ;
if (
if (
@ -78,7 +78,7 @@
}
}
} ) ;
} ) ;
return this . each ( function ( ) {
return this . each ( function ( ) {
// Get references to everything we're interested in
// Get references to everything we're interested in
var $this = $ ( this ) ,
var $this = $ ( this ) ,
@ -225,7 +225,7 @@
}
}
// Get extra ones defined on the element's data attributes
// Get extra ones defined on the element's data attributes
$ . each ( $this . data ( ) , function ( i , el ) {
$ . each ( $this . data ( ) , function ( i , el ) {
var parts = i . replace ( /([A-Z])/g , ",$1" ) . split ( "," ) ;
var parts = i . replace ( /([A-Z])/g , ",$1" ) . split ( "," ) ;
if ( parts [ 0 ] === "validation" && parts [ 1 ] ) {
if ( parts [ 0 ] === "validation" && parts [ 1 ] ) {
validatorNames . push ( parts [ 1 ] ) ;
validatorNames . push ( parts [ 1 ] ) ;
@ -242,7 +242,7 @@
do // repeatedly expand 'shortcut' validators into their real validators
do // repeatedly expand 'shortcut' validators into their real validators
{
{
// Uppercase only the first letter of each name
// Uppercase only the first letter of each name
$ . each ( validatorNames , function ( i , el ) {
$ . each ( validatorNames , function ( i , el ) {
validatorNames [ i ] = formatValidatorName ( el ) ;
validatorNames [ i ] = formatValidatorName ( el ) ;
} ) ;
} ) ;
@ -263,7 +263,7 @@
// Pull it out!
// Pull it out!
var validator = settings . builtInValidators [ el . toLowerCase ( ) ] ;
var validator = settings . builtInValidators [ el . toLowerCase ( ) ] ;
if ( validator . type . toLowerCase ( ) === "shortcut" ) {
if ( validator . type . toLowerCase ( ) === "shortcut" ) {
$ . each ( validator . shortcut . split ( "," ) , function ( i , el ) {
$ . each ( validator . shortcut . split ( "," ) , function ( i , el ) {
el = formatValidatorName ( el ) ;
el = formatValidatorName ( el ) ;
newValidatorNamesToInspect . push ( el ) ;
newValidatorNamesToInspect . push ( el ) ;
validatorNames . push ( el ) ;
validatorNames . push ( el ) ;
@ -282,30 +282,28 @@
var validators = { } ;
var validators = { } ;
$ . each ( validatorNames , function ( i , el ) {
$ . each ( validatorNames , function ( i , el ) {
// Set up the 'override' message
// Set up the 'override' message
var message = $this . data ( "validation" + el + "Message" ) ;
var message = $this . data ( "validation" + el + "Message" ) ;
var hasOverrideMessage = ( message !== undefined ) ;
var hasOverrideMessage = ( message !== undefined ) ;
var foundValidator = false ;
var foundValidator = false ;
message =
message =
(
(
message
message ?
? message
message :
: "'" + el + "' validation failed <!-- Add attribute 'data-validation-" + el . toLowerCase ( ) + "-message' to input to change this message -->"
"'" + el + "' validation failed <!-- Add attribute 'data-validation-" + el . toLowerCase ( ) + "-message' to input to change this message -->"
)
) ;
;
$ . each (
$ . each (
settings . validatorTypes ,
settings . validatorTypes ,
function ( validatorType , validatorTemplate ) {
function ( validatorType , validatorTemplate ) {
if ( validators [ validatorType ] === undefined ) {
if ( validators [ validatorType ] === undefined ) {
validators [ validatorType ] = [ ] ;
validators [ validatorType ] = [ ] ;
}
}
if ( ! foundValidator && $this . data ( "validation" + el + formatValidatorName ( validatorTemplate . name ) ) !== undefined ) {
if ( ! foundValidator && $this . data ( "validation" + el + formatValidatorName ( validatorTemplate . name ) ) !== undefined ) {
validators [ validatorType ] . push (
validators [ validatorType ] . push (
$ . extend (
$ . extend (
true ,
true , {
{
name : formatValidatorName ( validatorTemplate . name ) ,
name : formatValidatorName ( validatorTemplate . name ) ,
message : message
message : message
} ,
} ,
@ -330,7 +328,7 @@
} else {
} else {
$ . each (
$ . each (
settings . validatorTypes ,
settings . validatorTypes ,
function ( validatorTemplateType , validatorTemplate ) {
function ( validatorTemplateType , validatorTemplate ) {
if ( validators [ validatorTemplateType ] === undefined ) {
if ( validators [ validatorTemplateType ] === undefined ) {
validators [ validatorTemplateType ] = [ ] ;
validators [ validatorTemplateType ] = [ ] ;
}
}
@ -349,7 +347,7 @@
}
}
}
}
if ( ! foundValidator ) {
if ( ! foundValidator ) {
$ . error ( "Cannot find validation info for '" + el + "'" ) ;
$ . error ( "Cannot find validation info for '" + el + "'" ) ;
}
}
} ) ;
} ) ;
@ -361,36 +359,36 @@
$helpBlock . data (
$helpBlock . data (
"original-contents" ,
"original-contents" ,
(
(
$helpBlock . data ( "original-contents" )
$helpBlock . data ( "original-contents" ) ?
? $helpBlock . data ( "original-contents" )
$helpBlock . data ( "original-contents" ) :
: $helpBlock . html ( )
$helpBlock . html ( )
)
)
) ;
) ;
$helpBlock . data (
$helpBlock . data (
"original-role" ,
"original-role" ,
(
(
$helpBlock . data ( "original-role" )
$helpBlock . data ( "original-role" ) ?
? $helpBlock . data ( "original-role" )
$helpBlock . data ( "original-role" ) :
: $helpBlock . attr ( "role" )
$helpBlock . attr ( "role" )
)
)
) ;
) ;
$controlGroup . data (
$controlGroup . data (
"original-classes" ,
"original-classes" ,
(
(
$controlGroup . data ( "original-clases" )
$controlGroup . data ( "original-clases" ) ?
? $controlGroup . data ( "original-classes" )
$controlGroup . data ( "original-classes" ) :
: $controlGroup . attr ( "class" )
$controlGroup . attr ( "class" )
)
)
) ;
) ;
$this . data (
$this . data (
"original-aria-invalid" ,
"original-aria-invalid" ,
(
(
$this . data ( "original-aria-invalid" )
$this . data ( "original-aria-invalid" ) ?
? $this . data ( "original-aria-invalid" )
$this . data ( "original-aria-invalid" ) :
: $this . attr ( "aria-invalid" )
$this . attr ( "aria-invalid" )
)
)
) ;
) ;
@ -400,16 +398,16 @@
$this . bind (
$this . bind (
"validation.validation" ,
"validation.validation" ,
function ( event , params ) {
function ( event , params ) {
var value = getValue ( $this ) ;
var value = getValue ( $this ) ;
// Get a list of the errors to apply
// Get a list of the errors to apply
var errorsFound = [ ] ;
var errorsFound = [ ] ;
$ . each ( validators , function ( validatorType , validatorTypeArray ) {
$ . each ( validators , function ( validatorType , validatorTypeArray ) {
if ( value || value . length || ( params && params . includeEmpty ) || ( ! ! settings . validatorTypes [ validatorType ] . blockSubmit && params && ! ! params . submitting ) ) {
if ( value || value . length || ( params && params . includeEmpty ) || ( ! ! settings . validatorTypes [ validatorType ] . blockSubmit && params && ! ! params . submitting ) ) {
$ . each ( validatorTypeArray , function ( i , validator ) {
$ . each ( validatorTypeArray , function ( i , validator ) {
if ( settings . validatorTypes [ validatorType ] . validate ( $this , value , validator ) ) {
if ( settings . validatorTypes [ validatorType ] . validate ( $this , value , validator ) ) {
errorsFound . push ( validator . message ) ;
errorsFound . push ( validator . message ) ;
}
}
@ -423,7 +421,7 @@
$this . bind (
$this . bind (
"getValidators.validation" ,
"getValidators.validation" ,
function ( ) {
function ( ) {
return validators ;
return validators ;
}
}
) ;
) ;
@ -433,8 +431,10 @@
// =============================================================
// =============================================================
$this . bind (
$this . bind (
"submit.validation" ,
"submit.validation" ,
function ( ) {
function ( ) {
return $this . triggerHandler ( "change.validation" , { submitting : true } ) ;
return $this . triggerHandler ( "change.validation" , {
submitting : true
} ) ;
}
}
) ;
) ;
$this . bind (
$this . bind (
@ -447,15 +447,15 @@
"keypress" ,
"keypress" ,
"change"
"change"
] . join ( ".validation " ) + ".validation" ,
] . join ( ".validation " ) + ".validation" ,
function ( e , params ) {
function ( e , params ) {
var value = getValue ( $this ) ;
var value = getValue ( $this ) ;
var errorsFound = [ ] ;
var errorsFound = [ ] ;
$controlGroup . find ( "input,textarea,select" ) . each ( function ( i , el ) {
$controlGroup . find ( "input,textarea,select" ) . each ( function ( i , el ) {
var oldCount = errorsFound . length ;
var oldCount = errorsFound . length ;
$ . each ( $ ( el ) . triggerHandler ( "validation.validation" , params ) , function ( j , message ) {
$ . each ( $ ( el ) . triggerHandler ( "validation.validation" , params ) , function ( j , message ) {
errorsFound . push ( message ) ;
errorsFound . push ( message ) ;
} ) ;
} ) ;
if ( errorsFound . length > oldCount ) {
if ( errorsFound . length > oldCount ) {
@ -479,11 +479,11 @@
if ( settings . options . semanticallyStrict && errorsFound . length === 1 ) {
if ( settings . options . semanticallyStrict && errorsFound . length === 1 ) {
// Only one? Being strict? Just output it.
// Only one? Being strict? Just output it.
$helpBlock . html ( errorsFound [ 0 ] +
$helpBlock . html ( errorsFound [ 0 ] +
( settings . options . prependExistingHelpBlock ? $helpBlock . data ( "original-contents" ) : "" ) ) ;
( settings . options . prependExistingHelpBlock ? $helpBlock . data ( "original-contents" ) : "" ) ) ;
} else {
} else {
// Multiple? Being sloppy? Glue them together into an UL.
// Multiple? Being sloppy? Glue them together into an UL.
$helpBlock . html ( "<ul role=\"alert\"><li>" + errorsFound . join ( "</li><li>" ) + "</li></ul>" +
$helpBlock . html ( "<ul role=\"alert\"><li>" + errorsFound . join ( "</li><li>" ) + "</li></ul>" +
( settings . options . prependExistingHelpBlock ? $helpBlock . data ( "original-contents" ) : "" ) ) ;
( settings . options . prependExistingHelpBlock ? $helpBlock . data ( "original-contents" ) : "" ) ) ;
}
}
} else {
} else {
$controlGroup . removeClass ( "warning error success" ) ;
$controlGroup . removeClass ( "warning error success" ) ;
@ -498,12 +498,12 @@
}
}
}
}
) ;
) ;
$this . bind ( "validationLostFocus.validation" , function ( ) {
$this . bind ( "validationLostFocus.validation" , function ( ) {
$controlGroup . removeClass ( "success" ) ;
$controlGroup . removeClass ( "success" ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ,
} ,
destroy : function ( ) {
destroy : function ( ) {
return this . each (
return this . each (
function ( ) {
function ( ) {
@ -532,17 +532,19 @@
) ;
) ;
} ,
} ,
collectErrors : function ( includeEmpty ) {
collectErrors : function ( includeEmpty ) {
var errorMessages = { } ;
var errorMessages = { } ;
this . each ( function ( i , el ) {
this . each ( function ( i , el ) {
var $el = $ ( el ) ;
var $el = $ ( el ) ;
var name = $el . attr ( "name" ) ;
var name = $el . attr ( "name" ) ;
var errors = $el . triggerHandler ( "validation.validation" , { includeEmpty : true } ) ;
var errors = $el . triggerHandler ( "validation.validation" , {
includeEmpty : true
} ) ;
errorMessages [ name ] = $ . extend ( true , errors , errorMessages [ name ] ) ;
errorMessages [ name ] = $ . extend ( true , errors , errorMessages [ name ] ) ;
} ) ;
} ) ;
$ . each ( errorMessages , function ( i , el ) {
$ . each ( errorMessages , function ( i , el ) {
if ( el . length === 0 ) {
if ( el . length === 0 ) {
delete errorMessages [ i ] ;
delete errorMessages [ i ] ;
}
}
@ -555,22 +557,24 @@
var errorMessages = [ ] ;
var errorMessages = [ ] ;
this . each ( function ( i , el ) {
this . each ( function ( i , el ) {
errorMessages = errorMessages . concat (
errorMessages = errorMessages . concat (
$ ( el ) . triggerHandler ( "getValidators.validation" ) ? $ ( el ) . triggerHandler ( "validation.validation" , { submitting : true } ) : [ ]
$ ( el ) . triggerHandler ( "getValidators.validation" ) ? $ ( el ) . triggerHandler ( "validation.validation" , {
submitting : true
} ) : [ ]
) ;
) ;
} ) ;
} ) ;
return ( errorMessages . length > 0 ) ;
return ( errorMessages . length > 0 ) ;
} ,
} ,
override : function ( newDefaults ) {
override : function ( newDefaults ) {
defaults = $ . extend ( true , defaults , newDefaults ) ;
defaults = $ . extend ( true , defaults , newDefaults ) ;
}
}
} ,
} ,
validatorTypes : {
validatorTypes : {
callback : {
callback : {
name : "callback" ,
name : "callback" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return {
return {
validatorName : name ,
validatorName : name ,
callback : $this . data ( "validation" + name + "Callback" ) ,
callback : $this . data ( "validation" + name + "Callback" ) ,
@ -579,13 +583,12 @@
lastFinished : true
lastFinished : true
} ;
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
if ( validator . lastValue === value && validator . lastFinished ) {
if ( validator . lastValue === value && validator . lastFinished ) {
return ! validator . lastValid ;
return ! validator . lastValid ;
}
}
if ( validator . lastFinished === true )
if ( validator . lastFinished === true ) {
{
validator . lastValue = value ;
validator . lastValue = value ;
validator . lastValid = true ;
validator . lastValid = true ;
validator . lastFinished = false ;
validator . lastFinished = false ;
@ -597,7 +600,7 @@
window ,
window ,
$this ,
$this ,
value ,
value ,
function ( data ) {
function ( data ) {
if ( rrjqbvValidator . lastValue === data . value ) {
if ( rrjqbvValidator . lastValue === data . value ) {
rrjqbvValidator . lastValid = data . valid ;
rrjqbvValidator . lastValid = data . valid ;
if ( data . message ) {
if ( data . message ) {
@ -606,7 +609,7 @@
rrjqbvValidator . lastFinished = true ;
rrjqbvValidator . lastFinished = true ;
rrjqbvThis . data ( "validation" + rrjqbvValidator . validatorName + "Message" , rrjqbvValidator . message ) ;
rrjqbvThis . data ( "validation" + rrjqbvValidator . validatorName + "Message" , rrjqbvValidator . message ) ;
// Timeout is set to avoid problems with the events being considered 'already fired'
// Timeout is set to avoid problems with the events being considered 'already fired'
setTimeout ( function ( ) {
setTimeout ( function ( ) {
rrjqbvThis . trigger ( "change.validation" ) ;
rrjqbvThis . trigger ( "change.validation" ) ;
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
}
}
@ -620,7 +623,7 @@
} ,
} ,
ajax : {
ajax : {
name : "ajax" ,
name : "ajax" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return {
return {
validatorName : name ,
validatorName : name ,
url : $this . data ( "validation" + name + "Ajax" ) ,
url : $this . data ( "validation" + name + "Ajax" ) ,
@ -629,13 +632,12 @@
lastFinished : true
lastFinished : true
} ;
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
if ( "" + validator . lastValue === "" + value && validator . lastFinished === true ) {
if ( "" + validator . lastValue === "" + value && validator . lastFinished === true ) {
return validator . lastValid === false ;
return validator . lastValid === false ;
}
}
if ( validator . lastFinished === true )
if ( validator . lastFinished === true ) {
{
validator . lastValue = value ;
validator . lastValue = value ;
validator . lastValid = true ;
validator . lastValid = true ;
validator . lastFinished = false ;
validator . lastFinished = false ;
@ -643,8 +645,8 @@
url : validator . url ,
url : validator . url ,
data : "value=" + value + "&field=" + $this . attr ( "name" ) ,
data : "value=" + value + "&field=" + $this . attr ( "name" ) ,
dataType : "json" ,
dataType : "json" ,
success : function ( data ) {
success : function ( data ) {
if ( "" + validator . lastValue === "" + data . value ) {
if ( "" + validator . lastValue === "" + data . value ) {
validator . lastValid = ! ! ( data . valid ) ;
validator . lastValid = ! ! ( data . valid ) ;
if ( data . message ) {
if ( data . message ) {
validator . message = data . message ;
validator . message = data . message ;
@ -652,18 +654,18 @@
validator . lastFinished = true ;
validator . lastFinished = true ;
$this . data ( "validation" + validator . validatorName + "Message" , validator . message ) ;
$this . data ( "validation" + validator . validatorName + "Message" , validator . message ) ;
// Timeout is set to avoid problems with the events being considered 'already fired'
// Timeout is set to avoid problems with the events being considered 'already fired'
setTimeout ( function ( ) {
setTimeout ( function ( ) {
$this . trigger ( "change.validation" ) ;
$this . trigger ( "change.validation" ) ;
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
}
}
} ,
} ,
failure : function ( ) {
failure : function ( ) {
validator . lastValid = true ;
validator . lastValid = true ;
validator . message = "ajax call failed" ;
validator . message = "ajax call failed" ;
validator . lastFinished = true ;
validator . lastFinished = true ;
$this . data ( "validation" + validator . validatorName + "Message" , validator . message ) ;
$this . data ( "validation" + validator . validatorName + "Message" , validator . message ) ;
// Timeout is set to avoid problems with the events being considered 'already fired'
// Timeout is set to avoid problems with the events being considered 'already fired'
setTimeout ( function ( ) {
setTimeout ( function ( ) {
$this . trigger ( "change.validation" ) ;
$this . trigger ( "change.validation" ) ;
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
} , 1 ) ; // doesn't need a long timeout, just long enough for the event bubble to burst
}
}
@ -676,107 +678,131 @@
} ,
} ,
regex : {
regex : {
name : "regex" ,
name : "regex" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { regex : regexFromString ( $this . data ( "validation" + name + "Regex" ) ) } ;
return {
regex : regexFromString ( $this . data ( "validation" + name + "Regex" ) )
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( ! validator . regex . test ( value ) && ! validator . negative )
return ( ! validator . regex . test ( value ) && ! validator . negative ) ||
|| ( validator . regex . test ( value ) && validator . negative ) ;
( validator . regex . test ( value ) && validator . negative ) ;
}
}
} ,
} ,
required : {
required : {
name : "required" ,
name : "required" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { } ;
return { } ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ! ! ( value . length === 0 && ! validator . negative )
return ! ! ( value . length === 0 && ! validator . negative ) ||
|| ! ! ( value . length > 0 && validator . negative ) ;
! ! ( value . length > 0 && validator . negative ) ;
} ,
} ,
blockSubmit : true
blockSubmit : true
} ,
} ,
match : {
match : {
name : "match" ,
name : "match" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
var element = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . data ( "validation" + name + "Match" ) + "\"]" ) . first ( ) ;
var element = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . data ( "validation" + name + "Match" ) + "\"]" ) . first ( ) ;
element . bind ( "validation.validation" , function ( ) {
element . bind ( "validation.validation" , function ( ) {
$this . trigger ( "change.validation" , { submitting : true } ) ;
$this . trigger ( "change.validation" , {
submitting : true
} ) ;
} ) ;
} ) ;
return { "element" : element } ;
return {
"element" : element
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( value !== validator . element . val ( ) && ! validator . negative )
return ( value !== validator . element . val ( ) && ! validator . negative ) ||
|| ( value === validator . element . val ( ) && validator . negative ) ;
( value === validator . element . val ( ) && validator . negative ) ;
} ,
} ,
blockSubmit : true
blockSubmit : true
} ,
} ,
max : {
max : {
name : "max" ,
name : "max" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { max : $this . data ( "validation" + name + "Max" ) } ;
return {
max : $this . data ( "validation" + name + "Max" )
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( parseFloat ( value , 10 ) > parseFloat ( validator . max , 10 ) && ! validator . negative )
return ( parseFloat ( value , 10 ) > parseFloat ( validator . max , 10 ) && ! validator . negative ) ||
|| ( parseFloat ( value , 10 ) <= parseFloat ( validator . max , 10 ) && validator . negative ) ;
( parseFloat ( value , 10 ) <= parseFloat ( validator . max , 10 ) && validator . negative ) ;
}
}
} ,
} ,
min : {
min : {
name : "min" ,
name : "min" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { min : $this . data ( "validation" + name + "Min" ) } ;
return {
min : $this . data ( "validation" + name + "Min" )
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( parseFloat ( value ) < parseFloat ( validator . min ) && ! validator . negative )
return ( parseFloat ( value ) < parseFloat ( validator . min ) && ! validator . negative ) ||
|| ( parseFloat ( value ) >= parseFloat ( validator . min ) && validator . negative ) ;
( parseFloat ( value ) >= parseFloat ( validator . min ) && validator . negative ) ;
}
}
} ,
} ,
maxlength : {
maxlength : {
name : "maxlength" ,
name : "maxlength" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { maxlength : $this . data ( "validation" + name + "Maxlength" ) } ;
return {
maxlength : $this . data ( "validation" + name + "Maxlength" )
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( ( value . length > validator . maxlength ) && ! validator . negative )
return ( ( value . length > validator . maxlength ) && ! validator . negative ) ||
|| ( ( value . length <= validator . maxlength ) && validator . negative ) ;
( ( value . length <= validator . maxlength ) && validator . negative ) ;
}
}
} ,
} ,
minlength : {
minlength : {
name : "minlength" ,
name : "minlength" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
return { minlength : $this . data ( "validation" + name + "Minlength" ) } ;
return {
minlength : $this . data ( "validation" + name + "Minlength" )
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( ( value . length < validator . minlength ) && ! validator . negative )
return ( ( value . length < validator . minlength ) && ! validator . negative ) ||
|| ( ( value . length >= validator . minlength ) && validator . negative ) ;
( ( value . length >= validator . minlength ) && validator . negative ) ;
}
}
} ,
} ,
maxchecked : {
maxchecked : {
name : "maxchecked" ,
name : "maxchecked" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
var elements = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . attr ( "name" ) + "\"]" ) ;
var elements = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . attr ( "name" ) + "\"]" ) ;
elements . bind ( "click.validation" , function ( ) {
elements . bind ( "click.validation" , function ( ) {
$this . trigger ( "change.validation" , { includeEmpty : true } ) ;
$this . trigger ( "change.validation" , {
includeEmpty : true
} ) ;
} ) ;
} ) ;
return { maxchecked : $this . data ( "validation" + name + "Maxchecked" ) , elements : elements } ;
return {
maxchecked : $this . data ( "validation" + name + "Maxchecked" ) ,
elements : elements
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( validator . elements . filter ( ":checked" ) . length > validator . maxchecked && ! validator . negative )
return ( validator . elements . filter ( ":checked" ) . length > validator . maxchecked && ! validator . negative ) ||
|| ( validator . elements . filter ( ":checked" ) . length <= validator . maxchecked && validator . negative ) ;
( validator . elements . filter ( ":checked" ) . length <= validator . maxchecked && validator . negative ) ;
} ,
} ,
blockSubmit : true
blockSubmit : true
} ,
} ,
minchecked : {
minchecked : {
name : "minchecked" ,
name : "minchecked" ,
init : function ( $this , name ) {
init : function ( $this , name ) {
var elements = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . attr ( "name" ) + "\"]" ) ;
var elements = $this . parents ( "form" ) . first ( ) . find ( "[name=\"" + $this . attr ( "name" ) + "\"]" ) ;
elements . bind ( "click.validation" , function ( ) {
elements . bind ( "click.validation" , function ( ) {
$this . trigger ( "change.validation" , { includeEmpty : true } ) ;
$this . trigger ( "change.validation" , {
includeEmpty : true
} ) ;
} ) ;
return { minchecked : $this . data ( "validation" + name + "Minchecked" ) , elements : elements } ;
} ) ;
return {
minchecked : $this . data ( "validation" + name + "Minchecked" ) ,
elements : elements
} ;
} ,
} ,
validate : function ( $this , value , validator ) {
validate : function ( $this , value , validator ) {
return ( validator . elements . filter ( ":checked" ) . length < validator . minchecked && ! validator . negative )
return ( validator . elements . filter ( ":checked" ) . length < validator . minchecked && ! validator . negative ) ||
|| ( validator . elements . filter ( ":checked" ) . length >= validator . minchecked && validator . negative ) ;
( validator . elements . filter ( ":checked" ) . length >= validator . minchecked && validator . negative ) ;
} ,
} ,
blockSubmit : true
blockSubmit : true
}
}
@ -847,19 +873,18 @@
}
}
} ;
} ;
var formatValidatorName = function ( name ) {
var formatValidatorName = function ( name ) {
return name
return name
. toLowerCase ( )
. toLowerCase ( )
. replace (
. replace (
/(^|\s)([a-z])/g ,
/(^|\s)([a-z])/g ,
function ( m , p1 , p2 ) {
function ( m , p1 , p2 ) {
return p1 + p2 . toUpperCase ( ) ;
return p1 + p2 . toUpperCase ( ) ;
}
}
)
) ;
;
} ;
} ;
var getValue = function ( $this ) {
var getValue = function ( $this ) {
// Extract the value we're talking about
// Extract the value we're talking about
var value = $this . val ( ) ;
var value = $this . val ( ) ;
var type = $this . attr ( "type" ) ;
var type = $this . attr ( "type" ) ;
@ -882,31 +907,31 @@
* http : //stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string#answer-359910
* http : //stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string#answer-359910
* Short link : http : //tinyurl.com/executeFunctionByName
* Short link : http : //tinyurl.com/executeFunctionByName
* * /
* * /
function executeFunctionByName ( functionName , context /*, args*/ ) {
function executeFunctionByName ( functionName , context /*, args*/ ) {
var args = Array . prototype . slice . call ( arguments ) . splice ( 2 ) ;
var args = Array . prototype . slice . call ( arguments ) . splice ( 2 ) ;
var namespaces = functionName . split ( "." ) ;
var namespaces = functionName . split ( "." ) ;
var func = namespaces . pop ( ) ;
var func = namespaces . pop ( ) ;
for ( var i = 0 ; i < namespaces . length ; i ++ ) {
for ( var i = 0 ; i < namespaces . length ; i ++ ) {
context = context [ namespaces [ i ] ] ;
context = context [ namespaces [ i ] ] ;
}
}
return context [ func ] . apply ( this , args ) ;
return context [ func ] . apply ( this , args ) ;
}
}
$ . fn . jqBootstrapValidation = function ( method ) {
$ . fn . jqBootstrapValidation = function ( method ) {
if ( defaults . methods [ method ] ) {
if ( defaults . methods [ method ] ) {
return defaults . methods [ method ] . apply ( this , Array . prototype . slice . call ( arguments , 1 ) ) ;
return defaults . methods [ method ] . apply ( this , Array . prototype . slice . call ( arguments , 1 ) ) ;
} else if ( typeof method === 'object' || ! method ) {
} else if ( typeof method === 'object' || ! method ) {
return defaults . methods . init . apply ( this , arguments ) ;
return defaults . methods . init . apply ( this , arguments ) ;
} else {
} else {
$ . error ( 'Method ' + method + ' does not exist on jQuery.jqBootstrapValidation' ) ;
$ . error ( 'Method ' + method + ' does not exist on jQuery.jqBootstrapValidation' ) ;
return null ;
return null ;
}
}
} ;
} ;
$ . jqBootstrapValidation = function ( options ) {
$ . jqBootstrapValidation = function ( options ) {
$ ( ":input" ) . not ( "[type=image],[type=submit]" ) . jqBootstrapValidation . apply ( this , arguments ) ;
$ ( ":input" ) . not ( "[type=image],[type=submit]" ) . jqBootstrapValidation . apply ( this , arguments ) ;
} ;
} ;
} ) ( jQuery ) ;
} ) ( jQuery ) ;