Fix Remote Validation in JQuery Validation Plugin

Fix Remote Validation in JQuery Validation Plugin

Hi, I found a bug inside the JQuery Validation Plugin this happend when you use remote validation like username validation, once you focus out the field the validation run ok, but if you don't change the username entered and then you click again into the field and again make a focusout you will see [Object object] or the url for the validation.

The Fix.

1) into the Remote handler you must add the follow.

  - Before
  1.    return previous.valid;
 
  - After
  1. else if( previous.old === value && previous.valid === false){
  2.                             //FIX REMOTE MESSAGE TWICE ON BLUR
  3.                             //RETURN DE PREVIOUS OBJECT DIRECTLY
  4.                             return "same";
  5.                         }
  6.                         
  7.                         return previous.valid;

2) In the check handler you must add the following



  1.                                         if(result == "same"){
  2.                                             var errors = {};
  3.                                             var previous = this.previousValue(element); 
  4.                                             errors[element.name] = $.isFunction(previous.message) ? previous.message(previous.old) : previous.old;
  5.                                             this.showErrors(errors);
  6.                                             return false;
  7.                                         }
  8. if( !result ) {
  9.     this.formatAndAdd( element, rule );
  10.     return false;
  11. }