function
validate
( options ) {
// if nothing is selected, return nothing; can't chain anyway
if
(
!
this
.
length
) {
if
( options
&&
options.debug
&&
window
.
console
) {
console
.warn
(
"Nothing selected, can't validate, returning nothing."
);
}
return
;
}
// check if a validator for this form was already created
var validator
$
.
data
(
this
[
0
],
"validator"
);
if
( validator ) {
return
validator;
}
// Add novalidate tag if HTML5.
this
.attr(
"novalidate"
,
"novalidate"
);
validator
new
$
.validator( options,
this
[
0
] );
$
.
data
(
this
[
0
],
"validator"
, validator );
if
( validator.settings.onsubmit ) {
this
.validateDelegate(
":submit"
,
"click"
, function(
event
) {
if
( validator.settings.submitHandler ) {
validator.submitButton
event
.
target
;
}
// allow suppressing validation by adding a cancel class to the submit button
if
(
$
(
event
.
target
).hasClass(
"cancel"
) ) {
validator.cancelSubmit
true
;
}
// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if
(
$
(
event
.
target
).attr(
"formnovalidate"
)
!==
undefined
) {
validator.cancelSubmit
true
;
}
});