email1: {
required: true,
blacklist: true,
beanEmailValidator: true,
minlength: 6,
maxlength: 70,
remote: {
type: "GET",
url: llbFieldValJSONURL,
data: {
fieldData : function() {
return $("#enterEmail").val();
}
},
dataType:"json",
dataFilter: function(data) {
var json = jQuery.parseJSON(data);
if(json.error == "true") {
return "\"" + json.errorMessage + "\"";
} else {
return success;
}
}
}
}
This function check the uniqueness of a username and returns an error if not unique. The issue is that the remote method won’t make any additional calls after being valid.. I need it to trigger every time a value is entered/changed.
For example, if I enter 3 non-unique usernames, the call is made every time. If I enter a unique username, the call is made correctly and the username comes back as valid. So the field is then valid. Now if I enter another non-unique (invalid) username, the remote method won’t trigger again.
Wondering if it’s somehow caching the response?
invalid (non-unique) response:
{"error":"true","errorMessage":"<b>The User Name you chose is already in use.</b> Please enter another name."}
valid (unique) response:
{"error":"false","errorMessage":""}
Edit
Saw this on SO:
https://stackoverflow.com/a/1821667/335514
$("#site").change(function() {
$("#email").removeData("previousValue");
});
So the plugin seems to be caching the response. Does the plugin have a method to switch off caching, or would adding a cache: false to the ajax call do the same thing?
Edit
Neither of these methods worked. It appears that once a field is marked valid, it won’t make the remote call again. Thoughts on how to fix? Would putting the function into it’s own addMethod prevent this scenario?
UPDATE/SOLUTION:
Looking at the source code of
jquery.validate.js, particularly this snippet:Since the response is evaluated as JSON, you are expected to call
return "true". This is also pointed out in the documentationHowever, it can be quite confusing when looking at the source code that does an exactly equals test for true, if you neglect the fact that the following is implicitly set
dataType: jsonend update
Upon investigating some more, I’d say that your ‘dataFilter’ should not be returning ‘success’
Refer to Callback function queues @ http://api.jquery.com/jQuery.ajax/
My guess is that your JS breaks on trying to do
return successand thus no further validation requests are sent