[validate] Dynamic form; Ajax check if the field exist.

[validate] Dynamic form; Ajax check if the field exist.

Hi folks !

* For easier understanding reason, I will use "client" to designate the user.

So here's the situation; I've a dynamic form. If the client want to change is user name, he must click on a static link, and then a user input box appear. Then the client can change the value of his user name.... and I have an AJAX validation that check if that username is available or not.

Actually, I have made theses rules, and it work well if the client change his username:
  1. user: {
  2.    required: {
  3.       depends: function() {
  4.          return $('#user').length==1;              
  5.        }
  6.    },
  7.    remote: {
  8.       url: "ajaxCheckIfUserExist.php",
  9.       type: "post",
  10.       data: {
  11.          reverseCheck: true
  12.       }
  13.    }
  14. }

So the field is only required if it exist.
But the problem is that the AJAX validation is executed no matter is the field exist or not. And when the client don't want to change his username, the user field doesn't exist, and the validate plugin crash:

How can I make the ajax validation happen ONLY if the user field exist ?
Can we put a depends statement in the remote ... thing/fonction/method ?