8

I'm trying to use this validator: http://posabsolute.github.com/jQuery-Validation-Engine/ I load it just when a page has a form. But I have several pages with 2 form, both are loading with ajax. So, I need to check for each form before load: is the Validator loaded or not. how can I to check this? Thanks.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Denis Monn
  • 363
  • 4
  • 15

3 Answers3

22

You can check for the existence of $.validator:

if ($.validator) {
    // $.validator is defined
}
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
0

The plugin adds a validationPlugin function to jQuery.fn, so simply check whether it exists or not;

if (typeof jQuery.fn.validationPlugin === "function") {
    // It's loaded
} else {
    // It's not.
}
Matt
  • 74,352
  • 26
  • 153
  • 180
0

This works with ValidationEngine 2.6.2:

if (typeof jQuery.fn.validationEngine === "function") {
    // It's loaded
} else {
    // It's not.
}
bart
  • 14,958
  • 21
  • 75
  • 105