'Jquery validate is not working on boolean value
Hi so I have a modal with a bool value from my Model for site occupied, for reason it is causing my validate form to be ignored and I cant work out why. if I remove the code block for Occupied When Visited the validation works fine. I dont need to validate this check box so is there any way I can ignore it in validate? I have tried using ignore: siteOccupied, no luck, tried giving it its own class ignore: ".ignore", no luck either. any help would be appreciated
<div class="modal fade" id="submitRecordModal" tabindex="-1" aria-labelledby="submitRecordModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="alert alert-danger" id="invalidModel">
<span>
Please fill out all fields marked with a *
</span>
</div>
<div class="modal-header">
<h5 class="modal-title" id="submitRecordModalLabel">Site Visit Check</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="post" id="submitRecordForm">
<div>
<label class="form-label fw-bolder">Debt</label>
<div class="form-check mb-3 ignore">
<input class="form-check-input" type="checkbox" id="siteOccupied" name="siteOccupied" asp-for="@Model.Account.OccupiedWhenVisited">
<label class="form-check-label" for="siteOccupied">
Occupied When Visited
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="loiLeft" asp-for="@Model.Account.DebtChecks["LoiLeft"]">
<label class="form-check-label" for="loiLeft">
LOI Left
</label>
</div>
<div class="row gy-2 gx-3 align-items-center mb-3">
<div class="col-auto">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="contactCustomer" asp-for="@Model.Account.DebtChecks["ContactWithCustomer"]">
<label class="form-check-label">
Contact With Customer
</label>
</div>
</div>
<div class="col-auto">
<input type="text" class="form-control" id="contactName" name="contactName" asp-for="Account.ContactName">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
<button type="submit" form="submitRecordForm" asp-page-handler="SavetoDB" class="btn btn-primary">Submit Changes</button>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js"></script>
<script>
$(document).ready(function () {
$("#submitRecordForm").validate({
ignore: ".ignore",
rules: {
contactName: {
required: "#contactCustomer:checked"
},
},
messages: {
contactName: {
required: "Please enter some data",
}
}
});
});
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
