IMHO, Set a data id attribute with 'id' in your button markup and then use jQuery:
<button style="border:none; background:none; width:25px; color:#428bca;" class="glyphicon glyphicon-trash" id="confirm" data-toggle="modal" href="#" data-target="#delCustomer" data-id="{{$customer->id}}"></button>
Now, using jQuery you can pass this id to any child element of the modal:
$('#confirm').click(function(event){
event.preventDefault();
var id = $(this).data('id');
//console.log(id);
// pass id to appropriate element here
});
Hope this helps :)
Thanks that is definitely helpful.
I still can't get it working. Where you pass id to appropriate elemtent, not sure i have this correct. Think i need a jquery class.
$('#confirm').click(function(event){
event.preventDefault();
var id = $(this).data('id');
// console.log(id);
// pass id to appropriate element here
$(".modal-header #id").val(id);
});
also....
<button href="#" type="button" onClick="return confirmChange( {{$id}} )"></button>
<script>
function confirmChange(id)
{
var answer = confirm("Would you like to ...?");
if(answer==true) {
//do something
return false;
}else{
//do something
return false;
}
</script>
What element inside the modal you want to pass the id? would you paste the modal markup?
Here is what i have. Trying to confirm on delete using a modal.
My button
<button style="border:none; background:none; width:25px; color:#428bca;" class="glyphicon glyphicon-trash" id="confirm" data-toggle="modal" href="#" data-target="#delCustomer" data-id="{{$customer->id}}"></button>
My jquery
$('#confirm').click(function(event){
event.preventDefault();
var id = $(this).data('id');
// console.log(id);
// pass id to appropriate element here
$(".modal-header #id").val(id);
});
my modal
<!-- Modal -->
<div class="modal fade" id="delCustomer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"><span style="color:red;" class="glyphicon glyphicon-warning-sign"> </span> <p id="id"></p> ARE YOU SURE you want to delete {{$customer->firstName}} {{$customer->lastName}}
</h4>
</div>
<div class="modal-body">
If you delete this customer, everything associated with them (memberships, parties, etc...) will be permanently removed from the system.
</div>
<div class="modal-footer">
<div id="delmodelcontainer" style="float:right">
<div id="yes" style="float:left; padding-right:10px">
{{ Form::open(array('action' => array('CustomersController@destroy', $customer->id), 'method' => 'DELETE')) }}
{{Form::submit('Yes', array('class' => 'btn btn-primary'))}}
{{ Form::close() }}
</div> <!-- end yes -->
<div id="no" style="float:left;">
<button type="button" class="btn btn-defualt" data-dismiss="modal">No</button>
</div><!-- end no -->
</div> <!-- end delmodelcontainer -->
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Also I found these two helpful links... will definitely help you: http://stackoverflow.com/questions/8982295/confirm-delete-modal-dialog-with-twitter-bootstrap jsfiddle.net/MjmVr/3/
Try these approaches and see if it helps!
I did something similar, I have a list of subscriptions for a user and each subscription has a cancel link. When I load the page I go ahead and give each cancel link the actual url to the controller action that will cancel it ( .../subscription/cancel/{{ $id }} ). I then throw this javascript in which targets all of the cancel links:
$('.toggle-modal').on('click', function (e) {
e.preventDefault();
$('#cancel-sub-button').attr('href', $(this).attr('href'));
$('#myModal').modal('show');
})
The jQuery stops the link from going to the cancel action, brings up the modal and sets the modals cancel confirmation link (#cancel-sub-button) to the cancel link of the clicked item by using $(this). If they click the modal cancel link it will go to the controller just like normal.
Probably not the most elegant thing in the world but it has been working well in a live project.
Hope it helps!
If a modal it's not a Must, you can simply do it in a form submit
<input type="button" class="btn btn-danger" onsubmit="return confirm('Are you sure to delete the customer: {{ $customer->name }}')" >
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community