Reputation: 309
I'm using Bootstrap modal popup to show content in popup and I'm using if/else condition to open modal popup. I don't want to open modal popup when condition is false. My code:
<a data-toggle="modal" class="btn btn-primary" style="font-size: 10px" href="#" data-target="#myModal" title="Edit"><span class="glyphicon glyphicon-pencil"></span>Edit</a>
My jQuery is:
$('a[data-target=#myModal]').on('click', function (ev) {
ev.preventDefault();
if (filters.length <= 0) {
alert('Please select any one item in grid');
}
else {
$(this).attr('href', '/GeoRegion/Edit/' + filters[0]);
var target = $(this).attr("href");
// load the url and show modal on success
$("#myModal").load(target, function () {
$("#myModal").modal("show");
});
}
});
If filters.length<=0 then I don't want to open popup. Now popup opening with empty content.
Upvotes: 8
Views: 25715
Reputation: 121
//insert this code in your condition.
//for example.
if(...){
$('#myModal').modal('show');
}
Upvotes: 1
Reputation: 5424
The problem is that you have data-toggle="modal"
on your button, which is the data-attributes (HTML5) way of using modals. this will work without any javascript written.
remove data-toggle
and then your javascript should run correctly.
Upvotes: 13
Reputation: 38102
Try to do:
if (filters.length <= 0) {
$("#myModal").modal("hide");
}
Upvotes: 7