admin管理员组文章数量:1425893
Bootstrap modal is closing when I click on "Ok" button showing from "alert()" function.
$("#expample").modal({
backdrop: 'static',
keyboard: false,
show: true
});
Below is my jquery:
$('.sendToUser').on('click', function (){
var selectedLyrics = $('#selectedLyricsInput').val();
if($("input[name='selectUserRadio']").is(":checked") == false){
alert('Please, select a user to send.');
return;
}
});
Although, hitting "Enter" or "Esc" on keyboard is working fine and also, clicking outside the modal; the modal is not closing which is fine.
Below is my html:
<div class="modal fade" id="userSelectionModal" tabindex="-1" role="dialog" aria-labelledby="userSelectionModal">
<div class="modal-dialog modal-likes" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Select User</h4>
</div>
<div class="modal-body">
<div style="margin-bottom: 50px;" id="populateUsers">
</div>
<input type="hidden" id="selectedLyricsInput" value="" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success sendToUser" data-dismiss="modal">Send</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
{{--<i class="fa fa-spinner fa-spin"></i>--}}
</div>
</div>
</div>
I am creating an alert popup from an event on the modal but when clicked on the "ok" of the alert() popup, it disappears.
How to prevent closing of the modal after clicking on "OK" on the alert popup?
Thanks
Bootstrap modal is closing when I click on "Ok" button showing from "alert()" function.
$("#expample").modal({
backdrop: 'static',
keyboard: false,
show: true
});
Below is my jquery:
$('.sendToUser').on('click', function (){
var selectedLyrics = $('#selectedLyricsInput').val();
if($("input[name='selectUserRadio']").is(":checked") == false){
alert('Please, select a user to send.');
return;
}
});
Although, hitting "Enter" or "Esc" on keyboard is working fine and also, clicking outside the modal; the modal is not closing which is fine.
Below is my html:
<div class="modal fade" id="userSelectionModal" tabindex="-1" role="dialog" aria-labelledby="userSelectionModal">
<div class="modal-dialog modal-likes" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Select User</h4>
</div>
<div class="modal-body">
<div style="margin-bottom: 50px;" id="populateUsers">
</div>
<input type="hidden" id="selectedLyricsInput" value="" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success sendToUser" data-dismiss="modal">Send</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
{{--<i class="fa fa-spinner fa-spin"></i>--}}
</div>
</div>
</div>
I am creating an alert popup from an event on the modal but when clicked on the "ok" of the alert() popup, it disappears.
How to prevent closing of the modal after clicking on "OK" on the alert popup?
Thanks
Share Improve this question edited Jun 15, 2017 at 11:28 Owais asked Jun 15, 2017 at 11:20 OwaisOwais 8602 gold badges13 silver badges32 bronze badges 1- Please add html – RahulB Commented Jun 15, 2017 at 11:25
4 Answers
Reset to default 1Your modal is closing, because you have data-dismiss="modal"
attribute on the .sendToUser
button. Removing this attribute should prevent the modal from closing.
You need to remove attribute data-dismiss="modal"
at the .sendToUser
element.
If you need to close modal, you just need to add the code:
$('#userSelectionModal').modal('hide')
use within your script
window.location = "..\path after validation"
also avoid data-dismiss="modal" in submit button
Simply instantiate a variable that's tied to the events firing within the modal window - to false, further set the variable to false when deemed necessary (e.g. to prevent closing the modal when the alert pops up), and then finally when the window should normally close, do a quick "if check" that assesses if the variable is finally true and if it is, fire off the functionality that lets the modal close. This ensures that the modal window will close only when you allow it.
本文标签: javascriptbootstrap modal closes when ok on alert() is clickedStack Overflow
版权声明:本文标题:javascript - bootstrap modal closes when ok on alert() is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745448607a2658779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论