Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 1 year ago.
0

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 :)

Last updated 1 year ago.
0

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);
});
Last updated 1 year ago.
0

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>
Last updated 1 year ago.
0

What element inside the modal you want to pass the id? would you paste the modal markup?

Last updated 1 year ago.
0

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 -->
Last updated 1 year ago.
0

Also I found these two helpful links... will definitely help you: http://stackoverflow.com/questions/8982295/confirm-delete-moda... jsfiddle.net/MjmVr/3/

Try these approaches and see if it helps!

Last updated 1 year ago.
0

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!

Last updated 1 year ago.
0

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 }}')" >

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ralanyo ralanyo Joined 6 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.