You can do it with auto modal closing behavior which uses the data-dismiss
attribute itself or with the manual modal opening (as i guess you are doing currently) , by subscribing to hide
event and use preventDefault
on the event.
$('yourmodalselector').on('hide',function(e){
if(yourConditionNotToCloseMet){
e.preventDefault();
}
});
Demo
Demo2
See Documentation
hide event event is fired immediately when the hide instance method has been called, which gets called wither way and this is the best place to prevent the modal from closing.