I think this is not complex one but I can't do it by myself. I am very thankful for your help.
I am going to submit a form with validation. It seems like my validations are not working properly. Because when the input fields are empty it's not showing an error message. And also when clicking the submit button it's not showing error message. This incident only happens when input fields are empty.
Here is my HTML:
<form name="department" id="department">
<div class="form-group">
<label for="example-text-input">Department Name</label>
<span id="errfnCustomer"></span>
<input class="form-control" type="text" placeholder="Enter Department Name" id="textDepartmentName" name="textDepartmentName1">
</div>
<div class="form-group">
<label for="example-text-input">Registation Number</label>
<span id="errfnCustomer2"></span>
<input class="form-control" type="text" placeholder="Enter Department Registation Number" id="textRegistationNumber" name="textRegistationNumber">
</div>
<div class="form-group">
<label for="example-text-input">Web Site</label>
<input class="form-control" type="text" placeholder="Web Site" id="textWebsite" name="textWebsite1">
</div>
<div class="form-actions">
<div class="form-group">
<input type="button" value="Register" class="btn pull-right" id="btnsubmit" style="background-color:#1e90ff; width: 100px; color: white; font-weight: bold" />
</div>
</div>
</div>
And jQuery:
$('#department').validate({
rules: {
textDepartmentName1: {
required: true,
minlength: 3,
},
textRegistationNumber: {
required: true,
minlength: 3
},
textWebsite1: {
required: true,
minlength: 3
}
},
submitHandler: $("#btnsubmit").click(function (form) {
var submitData = {
DepartmentId: saveStat,
DepartmentName: $('#textDepartmentName').val().trim(),
RegistationNumber: $('#textRegistationNumber').val(),
Website: $('#textWebsite').val(),
Email: $('#textEmail').val(),
Telephone01: $('#textTelephone01').val(),
Telephone02: $('#textTelephone02').val(),
Fax: $('#textFax').val(),
BranchId: $('#cmbGetBranch').val()
}
if (saveStat == 0) {
$.ajax({
dataType: 'json',
contentType: 'application/json; charset=utf-8',
cache: false,
async: false,
type: 'POST',
data: "{submitData:" + JSON.stringify(submitData) + "}",
url: "/Department/AddDepartment",
success: function (saveDepartment) {
if (saveDepartment.saveDepartment.DepartmentId != 0) {
refresh();
alert(saveDepartment.saveDepartment.DepartmentName + " Saved succesfully...!!!");
} else {
alert('warning' + " Department saving unsucsessful...!!!");
}
},
error: function (xhr, errorThrown) {
alert('Error...!!! Internal - 01');
}
});
} else {
$.ajax({
dataType: 'json',
contentType: 'application/json; charset=utf-8',
cache: false,
async: false,
type: 'POST',
data: "{submitData:" + JSON.stringify(submitData) + "}",
url: "/Department/UpdateDepartment",
success: function (updateDepartment) {
if (updateDepartment.updateDepartment.DepartmentId != "") {
alert(updateDepartment.updateDepartment.DepartmentName + " updated succesfully...!!!");
refresh();
} else {
alert("Department update error...!!!");
}
},
error: function (xhr, errorThrown) {
alert('Error...!!!');
}
});
}
grid();
})
});
requiredin you input's HTML.<input class="form-control" type="text" placeholder="Enter Department Name" id="textDepartmentName" name="textDepartmentName1" required>