Reputation: 41
I'm trying to use the jQuery validation plugin on a form. I've added an AJAX routine to validate one of the fields, the rest just need the regular validation methods.
Here's the code that I'm using.
$(document).ready(function(){
$.validator.addMethod("unique_rep", function(value, element){
$.ajax({
beforeSend: function(){
spinnerStart();
},
type: "POST",
url: "servertime3.php",
data: "unique_rep="+value,
dataType:"json",
success: function(msg){
spinnerStop(msg);
}
})
},"");
$("#register").validate({
rules: {
rep_id:{
unique_rep: true,
},
last_name:{
required: true,
minlength: 3
},
first_name:{
required: false,
minlength: 3
},
middle_initial:{
maxlength: 1,
},
email:{
required: false,
email: true
},
url:{
required: false,
url: true
}
}
})
});
spinnerStart() starts an in progress indicator next to the field.
spinnerStop() displays the result of the AJAX function which returns an array that contains 'ok' which is true or false to show if the function succeeded and 'text' which is details of what went wrong.
This works fine EXCEPT that it's not submitting. Where and how do I tell the validation plugin that the rep_id field is valid?
Thanks.
Upvotes: 1
Views: 190
Reputation: 21925
By having properties like required: true
you're setting up constraints for the plugin to match against. The idea is for it to tell you if the form is valid or not.
Your question is a bit ambiguous.... I would narrow down the problem a bit m ore and you might get more answers... BUT here is me shooting the hip..
$('form').submit(function(){
if($('form').valid()){
$('form').submit();
} else {
return false;
}
})
Upvotes: 0
Reputation: 234
I'm not sure that i understood your question, also i'm sure that you know this but you also need to attach validate() plugin to a form..
$("#myform").validate({
submitHandler: function(form) {
form.submit();
alert("submited!");
}
});
Upvotes: 1