I have a list of categories, from where I want to pass {{category.name}} to data into Bootstrap modal.
I want to achieve that when I click on the specific button, to show the name of the category in the modal as a message?
Categories
<div class="card mt-2">#foreach($categories as $category)
<ul class="list-group list-group-flush">
<li class="list-group-item">{{ $category->name}}
<a href="" class="btn btn-danger btn-sm ml-2 float-right"
onclick="handleDelete({{$category->id}})">Delete</a>
Edit
</li>
</ul>
#endforeach
</div>
From where I've tried to pass {{$category->name}} into div element, but It showing the last element from the loop.
Modal
<form action="" method="POST" id="deleteCategoryForm">
#csrf
#method('DELETE')
<div class="modal fade" id="deleteModalCenter" tabindex="-1" role="dialog" aria-labelledby="deleteModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Delete category</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete "{{$category->name}}" ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Go Back</button>
<button type="submit" class="btn btn-danger">Yes, Delete</button>
</div>
</div>
</div>
</div>
</form>
JS Script
<script>
function handleDelete(id){
event.preventDefault();
var form = document.getElementById('deleteCategoryForm');
console.log('Delete', form);
form.action = '/categories/' + id;
$('#deleteModalCenter').modal('show');
}
</script>
Thanks in advance
Related
i want to get value id from my table or my db , when i tried to delete one of the row (one of the data). I tried to expand my endforeach and it's just make the html become so weird. Um for more explaining here is my images.
Images confirm modal
yeah i just want to confirm the user if it clicked the delete button it will show a modal "are you sure you want to delete this?".So, the problem is, i don't know how to get the value id when i clicked the next delete button from the seccond row delete button, delete button from the third row delete button, delete button from the fourth row delete button (if there is a row bellow it) and so on.
here is my modal code
Modal Delete
<div class="m-2">
<div class="modal fade h-50" id="modalDelete" tabindex="-1" role="dialog" aria-
labelledby="deleteModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Change Department Status</h5>
</div>
<div class="modal-body">
<p id="question">Are You sure want to delete {{$ideaprogram[0]->showidea_id}}?</p>
</div>
<div class="modal-footer">
<a id="deleteData">
<button type="button" class="btn btn-success">Yes</button>
</a>
<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
i'm just make the value of index $ideaprogram[0]->showidea_id like that. Using zero (0) the hardcode. for example if i want to delete the next one (the next index) which is 1, how can i change it the value into 1 or change it the value into 2 if i want to delete the next index and so on. Basically i want the function more like when i clicked the delete button from some row, it will show the id program from that row. I'm using laravel and php at the moment. I don't know how to make it happen. Can someone help me?
Set data in modal on delete button click :
assuming that you are showing your data in table , then give attribute data-programid to delete button.
#foreach($programs as $program)
<tr>
<td>{{$program->name}}</td>
<td><button class="btn btn-danger deleteProgram" data-programid="{{$program->id}}">Delete</button></td>
</tr>
#endforeach
now we set data in modal and show modal, when user click on deleteProgram button class javascript
<script>
$(document).on('click','.deleteProgram',function(){
var programID=$(this).attr('data-programid');
$('#app_id').val(programID);
$('#question').append(programID+' ?');
$('#applicantDeleteModal').modal('show');
});
</script>
your modal:
<div id="applicantDeleteModal" class="modal modal-danger fade" tabindex="-1" role="dialog" aria-labelledby="custom-width-modalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog" style="width:55%;">
<div class="modal-content">
<form action="{{route()}}" method="POST" class="remove-record-model">
{{ method_field('delete') }}
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h5 class="modal-title text-center" id="custom-width-modalLabel">Change Department Status</h5>
</div>
<div class="modal-body">
<h4 id="question">Are You sure want to delete </h4>
<input type="hidden" name="applicant_id" id="app_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger waves-effect remove-data-from-delete-form">Delete</button>
</div>
</form>
</div>
</div>
</div>
I use like this all time.
<td>
<ul style="list-style-type: none;">
<li><i class="fa fa-edit"></i> Edit </li>
<li><i class="fa fa-trash"></i>
<button data-toggle="modal" data-target="#modal{{ $role->id }}">Delete</button>
</li>
</ul>
</td>
<!-- Modal -->
<div class="modal fade" id="modal{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header bg-danger">
<h5 class="modal-title" id="exampleModalLabel">You are about to delete the role {{ $role->title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-danger">Once you delete, it cannot be undone.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form method="POST" action="{{ url('') }}/en/admin/role/delete/{{ $role->id }}">
{{ method_field('delete') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger">Confirm</button>
</form>
</div>
</div>
</div>
</div>
Actually i want an answer that give me a solutions more like A.A Noman since it will be good for a little line of code, so i tought it possible, but after trying the suggested solutions, and not give me that i want, so i think i can solve it like this.
script.js
function deleteModal(data){
document.getElementById('question').innerHTML = `Are you sure to delete ${data.showidea_id} ?`;
document.getElementById('deleteData').setAttribute('href',`/program_idea/${data.showidea_id}/deleteData`);
$('#modalDelete').modal('show');
}
and my HTML are like this
index.blade.php
#foreach($ideaprogram as $dataload)
<tr>
<td class="text-center">
<button type="button" class="btn btn-danger btn-sm deleteProgram" data-toggle="modal"
onclick="deleteModal({{$dataload}})">
<i class="far fa-trash-alt"></i>
</button>
</tr>
#endforeach
anyway thank you for everyone that answer my questions
Inside a view blade.php, I have a problem passing data within a foreach loop to a outside loop bootstrap modal.
show.blade.php:
{!! Form::open(['method' => 'PATCH','action' => ['OrderController#update',$order_items->id], 'class'=>'table_form']) !!}
#foreach($order_items as $oi)
<tr class="order-form-row">
<td>
{{ $oi->name }}
</td>
<td>
<a class="btn btn-block" data-toggle="modal" data-target="#deleteLineItemModal"><i class="icon-trash"></i></a>
</td>
</tr>
#endforeach
{!! Form::close() !!}
{{--bootstrap modal--}}
<div class="modal fade" id="deleteLineItemModal" tabindex="-1" role="dialog" aria-labelledby="deleteLineItemModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body edit-content">
<h5 class="text-center">Are you sure you want to delete this line item? {{$oi->id}}</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger pull-left">Yes, I am sure</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">No, not today</button>
</div>
</div>
</div>
</div>
When user click the delete icon for any record inside the table, it will pop up the modal to ask user if they want to delete selected row of record. How can I solve this problem?
You need to use javascript/jquery to pass values to modal.
{!! Form::open(['method' => 'PATCH','action' => ['OrderController#update',$order_items->id], 'class'=>'table_form']) !!}
#foreach($order_items as $oi)
<tr class="order-form-row">
<td>
{{ $oi->name }}
</td>
<td>
<a data-item="{{ $oi->id }}" class="btn btn-block" data-toggle="modal" data-target="#deleteLineItemModal"><i class="icon-trash"></i></a>
</td>
</tr>
#endforeach
{!! Form::close() !!}
{{--bootstrap modal--}}
<div class="modal fade" id="deleteLineItemModal" tabindex="-1" role="dialog" aria-labelledby="deleteLineItemModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body edit-content">
<h5 class="text-center">Are you sure you want to delete this line item? {{$oi->id}}</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger pull-left">Yes, I am sure</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">No, not today</button>
</div>
</div>
</div>
<script>
$(document).on("click", ".btn-block", function () {
var itemid= $(this).attr('data-item');
$("#lineitem").attr("href","/orders/line-item-delete/"+itemid)
});
</script>
I have a file that has two modals, one to remove a conference other to remove a registration type type.
The issue is that when I click in the "Remove" link to open the modal to remove the registration type that has a div with id "removeRtype" the modal that appears is always the modal to remove the conference that has a div with id "removeConference".
Do you know where is the issue?
The two modals code is below.
Remove Registration type modal:
Link to open registration type modal:
<label class="form-check-label" for="exampleRadios1">
{{$rtype->name}} <a data-toggle="modal" class="btn btn-sm btn-outline-light-gray ml-4"
id="removeRtype"
data-target=".bd-example-modal-lg" data-modal="removeRtype" href=""><i class="fa fa-times" aria-hidden="true"></i> Remove</a>
</label>
Modal to remove registration type:
<div class="modal fade bd-example-modal-lg" id="removeRtype" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel" data-modal="removeRtype">Remove registration type</h5>
<button type="button" class="close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row d-flex justify-content-center">
<p>Remove registtration type?</p>
<button class="btn btn-outline-primary" id="cancel_remove" href="#" data-dismiss="modal">No</button>
<a class="btn btn-primary ml-2" id="confirm_remove"
href="{{route('rtype.remove', ['id' => $conference->id])}}">No</a>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="close_login_modal" class="btn btn-primary"
data-dismiss="modal">Close
</button>
</div>
</div>
</div>
</div>
Link to open the modal to remove the conference:
#if($conference->registrations->count() == 0)
<a data-toggle="modal" class="btn btn-outline-light-gray ml-2" id="removeConference"
data-target=".bd-example-modal-lg" href="">Remover</a>
#endif
Modal to remove the conference:
<div class="modal fade bd-example-modal-lg" id="removeConference" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel" data-modal="removeConference">Remove conference</h5>
<button type="button" class="close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row d-flex justify-content-center">
<p>Remove conference?</p>
<button class="btn btn-outline-primary" id="cancel_remove" href="#" data-dismiss="modal">No</button>
<a class="btn btn-primary ml-2" id="confirm_remove"
href="{{route('conference.remove', ['id' => $conference->id])}}">No</a>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="close_login_modal" class="btn btn-primary"
data-dismiss="modal">Close
</button>
</div>
</div>
</div>
</div>
Try it like this :
The first :
<label class="form-check-label" for="exampleRadios1">
{{$rtype->name}}
<a data-toggle="modal" class="btn btn-sm btn-outline-light-gray ml-4" href="#removeRtype">
<i class="fa fa-times" aria-hidden="true"></i> Remove
</a>
</label>
The second :
#if($conference->registrations->count() == 0)
<a data-toggle="modal" class="btn btn-outline-light-gray ml-2"
href="#removeConference">Remover</a>
#endif
One more thing i see that you have the modal and the link with the same id, that's a problem :
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).
I am using bootstrap modal to display member's information. Each member has the button to open the modal. I have this button in loop:
#foreach($members as $member)
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal">View Details</button>
#endforeach
This modal content:
<div id="myModal" class="modal fade" 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">Member Detail Information</h4>
</div>
<div class="modal-body">
{{$member->name}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
But everytime I get the last member's information. This is obvious but i want to pass the $member->ID from the button and dispaly their respective details in the modal. How Can I acheive this?
You can use data attribute to pass some data into Bootstrap modal.
Buttons in the loop
#foreach()
<a data-toggle="modal" data-id="{{$member->name}}" href="#UserDialog" class="user_dialog">Details</a>
#endforeach
Bootstrap model
<div class="modal hide" id="UserDialog">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>some content</p>
<input type="text" name="user_name" id="user_name" value=""/>
</div>
</div>
And little JavaScript
$(document).on("click", ".user_dialog", function () {
var UserName = $(this).data('id');
$(".modal-body #user_name").val( UserName );
});
That's it
Little demo here : http://jsfiddle.net/Au9tc/6247/
I have this link where i open modal:
<li><i class="fa fa-times"></i></li>
And i have modal in seperate page modals.blade.php
<div class="modal fade modal_form" id="deleteProperty{{$property->id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel5" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="exampleModalLabel5">Are you sure you want to delete this property?</h4>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('user.property.delete',[$user->id,$property->id])}}">
<div class="form-group">
<div class="left-btn">
<button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
</div>
<div class="right-btn">
<button type="submit" class="btn btn-primary">Yes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
How can i pass this parameter ($property->id) to modal so when user click on specific property, to delete that property?
You need to pass the variables you want to use in the included views.
Example:
#include('standardUser.includes.modals', [ "property" => $property ])