I have a form which I am validating through the jQuery Validate plugin. Everything is working fine except just one thing.
I have a field that I using, the remote rule, and I am using AJAX to check if there is already an application record with the same name. I need to perform this validation only if the user changes the value in the field.
This is the validate code I have:
$('#createapp').validate({
rules: {
appname: {
minlength: 8,
required: true,
remote: {
url: "<?php echo base_url();?>app/application/check_app",
type:"POST",
async: false,
data: {
appname: function() {
return $("#appname").val();
}
}
}
},
apptitle: {
required: true
}
},
messages: {
appname: {
remote: "Application with same name already exists"
}
},
highlight: function(label) {
$(label).closest('.control-group').addClass('error');
},
success: function(label) {
label
.text('OK!').addClass('valid')
.closest('.control-group').addClass('success');
}
});
I need to do this:
Perform remote validation only if the user changes the text in the appname field. I tried using depends but am not able to make it work. This is basically what I tried:
remote: {
depends: function(element){
return ($('#appname').val() != "<?php echo trim($application[0]->app_name) ?>" );
}