Following is JS Code:
$('#createCust').on('click', function(e) {
e.preventDefault();
documentCommon.ajax({
dataType : 'text',
url : "/createcustomer",
data : $("body form:first").serialize(),
success : function(data) {
$(".dialogTitle").html("");
$(".dialogTitle").html("Add Customer");
$(".actualData").html("");
$(".actualData").html(data);
$('#modalViewDialog').modal('show');
}
});
});
Following is button:
<form:form method="POST" modelAttribute="customerForm"
class="form-signin" action="/createcustomer">
<form:input type="text" path="customerName" class="form-control"
placeholder="Customer Name" required="required"></form:input>
<button type="submit" id="createCust" class="btn btn-primary">Create</button>
When i remove JS code then it works fine but i want ajax call so i could not rely on whole page submit. Is there any way to enabled all required field check on JS call too?
Alternative way to achieve above is to check if the inputs are not empty using
!= ""and depending on this make your ajax call or show error .Here is an example if you know the name of inputs and want to check each input manually.
Demo Code :
If you have large form then you can just loop through all inputs inside form and check if
val()is not empty depending on this call your ajax or show errors .Modify below code according to your requirements.Demo code :