Here I am checking the input is already in db or not. I got the call back function response but it doesn't showing error if the function is false. I want to print that error message like other rules. The other rules error messages showing correctly.
On success of call back function returns 1 else returns 0
//html
<form action="" method="post" id="addGroup" name="addGroup">
<div class="form-group">
<label for="input-1">Name*</label>
<input type="text" class="form-control" name="Groupname" id="Groupname" placeholder="Enter Group Name" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-light px-5"><i class="icon-lock"></i> Add Group</button>
<a href="<?php echo base_url('admin/groups'); ?>"><button type="button" class="btn btn-light px-5"><i class="icon-lock"></i> Cancel</button></a>
</div>
</form>
// jquery validation
$( "#addGroup" ).validate({
errorClass: "invalid",
validClass: "success",
rules: {
Groupname: {
required: true,
minlength: 5,
onfocusout:function( element, event ) {
if (element.value != '' && element.value.length > 4) {
$.ajax({
url : '<?php echo base_url("admin/checkGroupName"); ?>',
type : 'post',
data : {"groupName":element.value},
success: function(data){
if (data)
return true;
else {
return false;
}
}
});
}
}
}
},
messages: {
Groupname: {
required: "Please provide a valid roup Name",
minlength: "Your group name must be at least 5 characters long",
onfocusout:"Group Name already exist"
}
},
submitHandler: function(form) {
form.submit();
}
});