I have gone through multiple links to validate modal and tried with the below code snippet. I am not sure what is the issue the modal is not validated and error messages are not showing up.
Here is my HTML
<button class="btn btn-primary" data-toggle="modal" data-target='#sendModal' type="button">Contact <span class="icon glyphicon "></span></button>
<div class="modal fade" id="sendModal" role="dialog">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="modal-title">Contact</h5>
</div>
<div class="modal-body">
<div class="form-group">
<label for="subject">Subject :</label>
<input class="form-control" id="subject" name="subject" type="text" >
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" id="check1"type="checkbox" name="sp[]" value="1" >
<label class="form-check-label" for="check1">
Check1
</label>
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input " id="check2" type="checkbox" name="sp[]"value="2" >
<label class="form-check-label" for="check2">
Check2
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="btnSend" class="btn btn-primary">Send </button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
Javascript function to validate
$(document).ready(function () {
$("#sendModal").validate({
rules: {
'sp[]': {
required: true,
minlength: 1
},
subject: "required"
},
messages: {
'sp[]': "Please select atleast one type of check",
subject: "Please enter subject"
}
});
$("#btnSend").click(function () {
var isValid = $("#sendModal").validate();
});
});
When i clicked on Send button,even though i did not enter subject
text box or did not check any check box,the form is getting submitted with out showing error messages.
Please let me know how to show error message when user did not check any check box and did not enter subject and message should show in red font color below text box and check box.