I am having a problem with the modal and the required fields on my application.
In one page, I have like 50 to 60 input fields, Some of them are required and some are not. I cannot just like check the value of every input using their ID
whether if its empty or not.
Currently, I added the required
class of bootstrap in every required input fields. And it is working fine as it focused on the empty required fields.
Additionally, I am also working on a modal on the same page. When I click the save button, the modal will open and show the acceptance message that the user will accept the terms and agreement.
After the user click the submit button inside the modal, and some required fields are empty, the tooltip of required class
will popup and focus on the empty field while the modal is open. Here is the Problem, when I close the modal, the required empty input will not be focused anymore.
Question is, Is it possible to closed the modal programmatically while not losing the focused and the tooltip on the required input?
code for button triggering the modal:
<a href="#" runat="server" id="btnUndertaking"
class="btn btn-success m-t-40" data-toggle="modal"
data-target="#myModal" data-backdrop="static" data-keyboard="false">
<i class="fa fa-floppy-o" aria-hidden="true"></i>SAVE</a>
here is the code for the modal:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">
<center>UNDERTAKING</center>
</h4>
</div>
<div class="modal-body">
<div runat="server" id="alert_box1" visible="false" class="alertalert alert-danger fade in">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<asp:Label runat="server" ID="lblalert1" Text=""></asp:Label>
</div>
<div class="row">
<div class="row">
<%-- <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">--%>
<div class="col-md-12">
<div class="white-box">
<p>
I/We hereby certify that all information in this form are true, correct
and complete. I/We understand and agree that: (a) all notices, requests,
demands and other communications shall be deemed to have duly given if sent
to the residential/ other address and/or e-mail address provided herein,
and (b) any misrepresentation and/or falsification of information in this
document is sufficient ground for the cancellation of my/our purchase.
</p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button runat="server" ID="cmdSubmit" Text="SUBMIT"
CssClass="btn btn-success"
OnClick="cmdSubmit_Click" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
EDITS
I have seen this question with an accepted answer. I am trying to do the same but it is not working with the modal.
I tried implementing this code but the tooltip of required
is not showing anymore.
function checkInputs() {
$('input').filter('[required]').each(function() {
if ($(this).val() === '') {
$('#btnUndertaking').prop('disabled', true)
isValid = false;
} else {
isValid = true;
}
});
if(isValid) {$('#btnUndertaking').prop('disabled', false)}
return isValid;
}
//Enable or disable button based on if inputs are filled or not
$('input').filter('[required]').on('keyup',function() {
checkInputs()
})