Reputation: 1439
I was coding front end screen for adding Edit features over fetched data from database.I have two kinds of data:
I used modal before when modal is needed in both cases, but Now you can notice that,modal will open if and only if status Not = 'yes'
I don't know that.please help me.thanks
var status = 'yes';
$('#edit').click(function() {
if(status == 'yes'){
//No Warning Modal Appear.So your data is Editable.
$('#myModal').modal('hide');
}
else{
//Warning Modal Appear.So your data Not Editable.
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id ='edit'>Edit</button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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">Modal Header</h4>
</div>
<div class="modal-body">
<p>the data status != 'yes'.Therefore,Warning Modal Appear.So your data Not Editable</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 436
Reputation: 20845
If it were me doing this, I would remove data-toggle="modal" data-target="#myModal"
and manage the modal display manually.
<script type="text/javascript">
$('#edit').click(function(){
if( conditions == true ) {
$('#myModal').modal('show');
}else{
// do nothing
}
});
</script>
Upvotes: 2