Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validation plugin: Nothing selected, can't validate, returning nothing

I have a large Rails project with over 80 js files, and I keep getting this message in Chrome's console:

Nothing selected, can't validate, returning nothing. 

I can't figure out what's throwing that message, though. All forms that I'm using the validation plugin on seem to correctly validate as they're supposed to.

How can I trace back to see which file or function is actually causing this message to appear?

Here's the relevant part from the validation plugin:

  // 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;
  }

It seems that validate() is being called on a non-existing selector, but I call validate() in hundreds of places throughout the project, which is why I'm looking for a way to trace the exact call to the validate() method.

like image 228
croceldon Avatar asked Oct 23 '13 19:10

croceldon


1 Answers

From the jQuery Validate plugin itself...

(function($) {
$.extend($.fn, {
    // http://docs.jquery.com/Plugins/Validation/validate
    validate: function( 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;
        }
 ....

So it seems something is very wrong with how you're using the plugin. The code would seem to indicate that you've not properly attached .validate() to your form element.


Quote OP:

"but I call validate() in hundreds of places throughout the project, which is why I'm looking for a way to trace the exact call to the validate() method."

Your console errors are only relevant to the page loaded in the browser. Surely you don't have hundreds of <form>...</form> objects loaded on the single page.


The console "warning" will only appear if you have debug: option set to true and it only means that .validate() is being called on a form that doesn't exist in the DOM. It's only a warning, not an error. Besides, you cannot really use the plugin with debug: set to true because the form will never submit.

"Enables debug mode. If true, the form is not submitted and certain errors are displayed on the console (will check if a window.console property exists). Try to enable when a form is just submitted instead of validation stopping the submit. Example: Prevents the form from submitting and tries to help setting up the validation with warnings about missing methods and other debug messages."

See: http://jqueryvalidation.org/validate/

like image 76
Sparky Avatar answered Oct 16 '22 09:10

Sparky