I used vue to populate the item list in my html, and what I want to do, is when the item is clicked, a modal would appear with the data of the clicked item. I'm not using boostrap-vue.
Html:
<div class="row">
<div class="col-lg-4 col-md-6" v-for="items in data" data-toggle="modal" data-target="#exampleModal" user="'items'" click="sendInfo(items)">
<a href="#" class="latest-product__item">
<div class="latest-product__item__pic">
<img src="img/latest-product/lp-1.jpg" alt="">
</div>
<div class="latest-product__item__text">
<h6>{{items.item_name}}</h6>
<div v-for="variant in items.variants">
<div v-for="store in variant.stores">
<span>{{store.default_price}}</span>
</div>
</div>
</div>
</a>
</div>
</div>
Modal:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<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>
</div>
<div class="modal-body">
<a href="#" class="latest-product__item">
<div class="latest-product__item__pic">
<img src="img/latest-product/lp-1.jpg" alt="">
</div>
<div class="latest-product__item__text">
<h6>{{items}}</h6>
<span>{{items}}</span>
</div>
</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-block">Add to Cart</button>
</div>
</div>
</div>
</div>
Vue:
window.onload = function () {
const access_token = "access token here";
new Vue({
el: '#item-data',
data () {
return {
data:[]
}
},
mounted () {
..... API calll .....
},
methonds:{
sendInfo(items) {
this.selectedUser = items;
}
}
})
}
I want to pass the data {{items.item_name}} and {{store.default_price}} to the modal. How do I achieve this?
create a variable for the value you want to pass, a method to handle the event:
data () {
return {
data:[],
passedData:{item_name:null, default_price:null}
},
methods:{
sendInfo(item){
this.passedData = item
}
}
and on the HTML part where you loop through the items:
<div class="col-lg-4 col-md-6" v-for="items in data" data-toggle="modal" data-target="#exampleModal" user="'items'" click="sendInfo(items)">
<div class="latest-product__item__pic">
<img src="img/latest-product/lp-1.jpg" alt="">
</div>
<div class="latest-product__item__text">
<h6>{{items.item_name}}</h6>
<div v-for="variant in items.variants">
<div v-for="store in variant.stores">
<span>{{store.default_price}}</span>
</div>
<a href="#" class="latest-product__item" #click="sendInfo({item_name:items.item_name,default_price:store.default_price})">
Show Modal
</a>
</div>
</div>
</div>
Modal:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<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>
</div>
<div class="modal-body">
<a href="#" class="latest-product__item">
<div class="latest-product__item__pic">
<img src="img/latest-product/lp-1.jpg" alt="">
</div>
<div class="latest-product__item__text">
<h6>{{passedData.item_name}}</h6>
<span>{{passedData.default_price}}</span>
</div>
</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-block">Add to Cart</button>
</div>
</div>
</div>
</div>
Use common Vue instance for modal and HTML block to access the same data as. Suppose:
<div id='#item-data'>
<div>
//basic Html code
<div>
<div>
//modal code
<div>
<div>
then you can access same vue instance variable in your HTML and modal.
I'm going to assume that your modal markup is somewhere inside the element with the ID 'item-data', and so has access to the data in your Vue instance.
The first thing you need to do is declare selectedUser as a data property, as Vue needs to know about it upfront:
data () {
return {
data:[],
selectedUser: null,
}
},
Next, you need to change your modal markup slightly, so it's referring to the currently selected item (e.g the heading would be {{selectedUser.item_name}} instead of {{items}}).
Lastly, the syntax is wrong where you're attaching a click handler to your item row. Instead of click="sendInfo(items)" it should be #click="sendInfo(items)".
Related
Thank you for reading this question.
Iam opening the modal from typescript code after some API success reponse.
It is binding normally after taking more time eventhough if iam not using timer.
Main thing is that if I inspect it wil show the modal data (dont know may be becouse scroll or refresh) and even if i wont mention timer also it wil bind very next after i inspect.
i just wanted to clarify i have used timer becouse after i inspect may be a scroll or refresh it was binding suddenly, i thought may be a symultaneous process of value assgn and opening a modal.
This my html
<div style="display: none">
<button class="primary" #myModalSuccess data-target="#myModalSuccess" data-toggle="modal"
style="cursor: pointer;">Delete</button>
<div id="myModalSuccess" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content" *ngIf="checkOutConfFromRazor">
<div class="modal-header">
<button type="button" (click)="checkSubscriptionAndInvitee()" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="text-center"><img style="height: 80px; " src="assets/img/dashboard/check_circle.svg"></div>
<div class="modal-body">
<h4 class="text-center primary">Payment successful</h4>
<p class="text-center location-text ">Your payment has been proccessed! <br>Details of your transaction are
listed below.
</p>
<div class="ver-divider"></div>
<div class="hor-line"></div>
<div class="ver-divider"></div>
<p class="text-center primary">Transaction ID : <span
class="text-right">{{checkOutConfFromRazor?.id}}</span> </p>
<div class="ver-divider"></div>
<div class="row">
<div class="col">
<label>Transaction Amount</label>
</div>
<div class="col text-right">
<label> {{checkOutConfFromRazor?.amount | slice:0:checkOutConfFromRazor?.amount?.length-2}}
₹</label>
</div>
</div>
<div class="ver-divider"></div>
<div class="hor-line"></div>
<div class="ver-divider"></div>
<div class="row">
<div class="col">
<label>Transaction date</label>
</div>
<div class="col text-right">
<label>{{checkOutConfFromRazor?.created_at | date}}</label>
</div>
</div>
<div class="text-center mt-4">
<button (click)="checkSubscriptionAndInvitee()" class="primary-button-big pl-5 pr-5 pt-1 pb-1"
data-dismiss="modal" style="border: none;">Close</button>
</div>
</div>
</div>
</div>
This is my .ts code
this.subscription = this.userService.verifyCheckOut(val.planId, JSON.stringify(response)).subscribe(value => {
if (value.isVerifyed) {
this.checkOutConfFromRazor = value.payment;
console.log("sucessData" + JSON.stringify(this.checkOutConfFromRazor));
setTimeout(() => {
this.myModalSuccess.nativeElement.click();
}, 20000);
} else {
this.checkOutConfFromRazor = value.payment;
this.myModalFailure.nativeElement.click();
}
});
The this.obj data is populated after modal window load. So, how can I sync both data and modal?
Acomponent.ts
this.dialog.showModal(this.referenceNumber);
dialogComponent.ts
export class DialogComponent {
obj:any;
showModal(name:String) {
if(name!==null) {
this.obj=name;
$("#myModal").modal('show');
}
}
hideModal():void {
document.getElementById('close-modal').click();
}
errorModal() {
$("#errorModal").modal('show');
}
}
dialog.html
<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>
</div>
<div class="modal-body">
<p>Record saved Successfully{{obj}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
The Angular approach is to control visibility of the modal via the javascript.
So something like:
<div *ngIf="showModal" 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" (click)="showModal=false">×</button>
</div>
<div class="modal-body">
<p>Record saved Successfully{{obj}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Note the *ngIf="showModal" and (click) event handler on the button.
Your .ts file would need a showModal: boolean; property, and the button click handler would need run change detection if you are using push change detection.
Edit:
And yes, don't use jQuery in Angular. I recommend the ng-bootstrap library.
I am working in an eCommerce application ,In this I have cart icon .What I want to do is when I click on the cart icon I want to show a modal screen with the user selected product data .
But in my case for the first time after page loads modal screen opens after double click,afterwards it opens with the single click .
icon :
<i class="fas fa-cart-plus fa-flip-horizontal text-primary" (click)="get_My_Cart($event)" data-toggle="modal" data-target="#exampleModal" style="font-size:25px;cursor: pointer;"></i>
Modal :
<div *ngIf="mycart && mycart.length" class="modal fade modalstyle" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header headerHeight text-white " style="background:rgb(0, 0, 0);font-weight:bold">
<h6 class="modal-title" id="exampleModalLabel">My Cart Items</h6>
<button #closeModalBtn type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div *ngFor="let products of mycart;let i =index;">
<div class="container col-sm-12">
<div class="row">
<div class="col-sm-4 paddingforimage">
<img [src]="products['ITEM_IMAGE_PATH']">
</div>
<div class="text-info col-sm-6">
<span>
<h6>{{products?.TOTAL_QTY}} × {{products?.ITEM_PRICE}} ₹</h6>
</span>
<span>
<h6>{{products?.ITEM_DESC}}</h6>
</span>
<span>
<h6>{{products?.TOTAL_AMT}} ₹</h6>
</span>
</div>
<div class="col-sm-1 text-right">
<button type="button" class="close closebtn" aria-label="Close" (click)="detele_My_Cart(products?.ITEM_CODE)">
<span aria-hidden="true" (click)="detele_My_Cart(products?.ITEM_CODE)">×</span>
</button>
</div>
</div>
</div>
<hr>
</div>
<div class=" container row col-sm-12">
<div class="col-sm-6">
<strong>SHIPPING</strong>
</div>
<div class="col-sm-6 text-right">0 ₹</div>
<hr>
<div class="col-sm-6">
<strong>TOTAL</strong>
</div>
<div class="col-sm-6 text-right">{{my_Cart_Total_Amount}} ₹</div>
</div>
<br>
<div class="container row col-sm-12" id="wrapper">
<button type="button" class="btn btn-success buttonSize" data-dismiss="modal" routerLink="/cartsummary">
<strong>CHECK OUT</strong>
</button>
</div>
</div>
</div>
</div>
</div>
Component:
get_My_Cart($event) {
this.publicIp.v4().then(ip => {
this.CartdataService.get_My_Cart_Products(ip).subscribe(
data => {
this.mycart = data['Table']
this.my_Cart_Total_Amount = data['Table1'][0]['TOTAL_AMOUNT']
});
});
}
Here in modal screen I have a validation ,Modal screen is open if data is bind in it otherwise it will not .(modal will not open if the cart is empty).
*ngIf="mycart && mycart.length"
If I remove this validation from the modal screen it works ,but it always opens (if there is no product in cart and user clicked on the cart icon it opens but I want to restrict it .)
can anyone tell me how to handle this issue ..
The flow of code is not correct.
Anyway, I think, you're using jQuery & Bootstrap.js. (Bad Idea)
You can programmatically trigger the modal using $('#exampleModal').modal('show') once data comes from server.
declare var $ :any;
get_My_Cart($event) {
this.publicIp.v4().then(ip => {
this.CartdataService.get_My_Cart_Products(ip).subscribe(
data => {
this.mycart = data['Table']
this.my_Cart_Total_Amount = data['Table1'][0]['TOTAL_AMOUNT']
if(this.mycart && this.mycart.length)
$('#exampleModal').modal('show')
});
});
}
But there is a simple workaround in this case. Try to toggle display property of CSS instead of removing it from DOM using *ngIf.
<div [ngStyle]="{display: mycart && mycart.length ? 'block':'none'}" class="modal fade modalstyle">
</div>
I’m working on a web application (Asp.Net MVC 5) where the user has to crate many data records with mappings to other records. The user must be able to create a mapping to an existing or newly created record.
A typical case would be the creation of an address:
User opens the site to create an address
He enters the normal fields like street and street no etc.
He can select an existing city (in which the address is located) from a table
If the required city does not already exist he can create a new city
… For the city, he can select a country or create on (same as for address and city)
The selection is implemented using bootstrap modals.
Pressing on a select button (like select city) shows a modal containing a table showing all the selectable records in a table.
The modal with the table contains an add new button to add new entities, which opens another modal.
To be able to reuse the views I’ve split the code in partial views like this:
_CreateAddress => Contains only the form to create an address
_CreateAddressModal => A modal containing _CreateAddress
_SelectAddressModal => A modal containing a table to showing all addresses. The modal contains also _CreateAddressModal which will be displayed when the user clicks on the add new button
_CreateCity => Contains only the form to create a city
_CreateCityModal => A modal containing _CreateAddressModal
_SelectCityModal => A modal containing a table to showing all cities. The modal contains also _CreateCityModal which will be displayed when the user clicks on the add new button
…and so on
I’ve two problems:
Clicking on a backdrop does not close the open modal
The backdrop of the topmost modal has a lower z-index than the all other modals and does therefore not hide the other modals
I’ve tried to set the z-index of the backdrops on modal show, to make sure they hide the other modals but this didn’t work => the backdrops get displayed above the current modal.
Here is a fiddle showing the problem: jsFiffle
SO does not let me link to a JSFiddle without adding the code to the question, so here is the code:
HTML:
<!-- Create Address -->
<div id="CreateAddress" class="modal fade fullScreen" tabindex="-1" role="dialog">
<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">Create Address</h4>
</div>
<div class="modal-body">
<div class="alert alert-info">
<strong>Placeholder</strong> Here is the form to create an address
<button class="btn btn-default" id="selectCityButton">select city</button>
</div>
<button class="btn btn-primary">OK (not implemented)</button>
<button class="btn btn-default modalCloseButton"
data-modalid="CreateAddress">Cancel</button>
</div>
</div>
</div>
</div>
<!-- Select City -->
<div id="SelectCity" class="modal fade fullScreen" tabindex="-1" role="dialog">
<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">Select a City</h4>
</div>
<div class="modal-body">
<div class="alert alert-info">
<strong>Placeholder</strong> Here is a table to select an existing city
</div>
<button class="btn btn-success btn-block" id="createCityButton">Create new city</button>
<button class="btn btn-primary">OK (not implemented)</button>
<button class="btn btn-default modalCloseButton"
data-modalid="SelectCity">Cancel</button>
</div>
</div>
</div>
</div>
<!-- Create City -->
<div id="CreateCity" class="modal fade fullScreen" tabindex="-1" role="dialog">
<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">Create City</h4>
</div>
<div class="modal-body">
<div class="alert alert-info">
<strong>Placeholder</strong> Here is the form to create a city
<button class="btn btn-default" id="selectCountryButton">select country of city</button>
</div>
<button class="btn btn-primary">OK (not implemented)</button>
<button class="btn btn-default modalCloseButton"
data-modalid="CreateCity">Cancel</button>
<!-- Select Country -->
<div id="SelectCountry" class="modal fade fullScreen" tabindex="-1" role="dialog">
<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">Select a Country</h4>
</div>
<div class="modal-body">
<div class="alert alert-info">
<strong>Placeholder</strong> Here is a table to select an existing country
</div>
<button class="btn btn-success btn-block" id="createCountryButton">Create new country</button>
<button class="btn btn-primary">OK (not implemented)</button>
<button class="btn btn-default modalCloseButton"
data-modalid="SelectCountry">Cancel</button>
</div>
</div>
</div>
</div>
<!-- Select Country END -->
<!-- Create Country -->
<div id="CreateCountry" class="modal fade fullScreen" tabindex="-1" role="dialog">
<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">Create Country</h4>
</div>
<div class="modal-body">
<div class="alert alert-info">
<strong>Placeholder</strong> Here is the form to create a country
</div>
<button class="btn btn-primary">OK (not implemented)</button>
<button class="btn btn-default modalCloseButton"
data-modalid="CreateCountry">Cancel</button>
</div>
</div>
</div>
</div>
<!-- Create Country END -->
</div>
</div>
</div>
</div>
<button class="btn btn-primary btn-block" id="openModal">Open Modal</button>
JS:
var zIndex = 10000;
// Displys the given modal on top of everything else
// modal: The modal to display as jQuery object
// Does not work => remove thw first two lines to see the problem
function displayModalOnTop(modal) {
// remove me
modal.modal('show');
return;
// end remove
zIndex += 2;
modal.css('z-index', zIndex);
modal.modal('show');
setTimeout(function () {
$('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
}, 0);
}
$(function(){
$('#openModal').on('click', function(){
displayModalOnTop($('#CreateAddress'));
});
// generic close modal handler
$('.modalCloseButton').on('click', function(){
var $this = $(this);
var modalId = $this.attr('data-modalid');
$('#' + modalId).modal('hide');
})
// Select city click
$('#selectCityButton').on('click', function(){
displayModalOnTop($('#SelectCity'));
});
// Create city click
$('#createCityButton').on('click', function(){
displayModalOnTop($('#CreateCity'));
});
// Select country click
$('#selectCountryButton').on('click', function(){
displayModalOnTop($('#SelectCountry'));
});
// Create country click
$('#createCountryButton').on('click', function(){
displayModalOnTop($('#CreateCountry'));
});
});
CSS:
.modal.fullScreen {
padding-left: 0 !important;
padding-right: 0 !important;
margin-top: 48px;
}
.modal.fullScreen .modal-content {
height: auto;
min-height: 100%;
border-radius: 0;
}
.modal.fullScreen .modal-body.noPadding {
padding: 0;
}
.modal.fullScreen .modal-dialog {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.modal.fullScreen .modal-header {
background-color: #3276b1;
color: #fff;
}
.modal.fullScreen .modal-header .close {
color: #FFF;
text-decoration: none;
cursor: pointer;
opacity: 0.4;
font-size: 30px;
}
.modal.fullScreen .modal-header .close:hover {
opacity: 1 !important;
}
The problem was that the modal covered the hole screen. The backdrop was visible due to the margin of the modal but was not clickable because it was totally covered by the modal.
Removing the margin from the modal and adding it to the modal dialog fixed the problem.
Rather then writing this much of code on your own and maintaining everything by your self what you can do is simply given in below snippet.
function simpleSHow(title)
{
var msg=$('#simple-div');
BootstrapDialog.show({
title : title,
message: $('#simple-div'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
function complexSHow(title)
{
var msg=$('#complex-div');
BootstrapDialog.show({
title : title,
message: $('#complex-div'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
function showDiv1(div_id)
{
var msg=$('#lavel-2_div-1');
BootstrapDialog.show({
title : 'Level 2 Title',
message: $('#lavel-2_div-1'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
function showDiv2(div_id)
{
var msg=$('#lavel-2_div-2');
BootstrapDialog.show({
title : 'Level 2 Title',
message: $('#lavel-2_div-2'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
function showDiv3(div_id)
{
var msg=$('#lavel-2_div-3');
BootstrapDialog.show({
title : 'Level 2 Title',
message: $('#lavel-2_div-3'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
function showDiv4(div_id)
{
var msg=$('#lavel-2_div-4');
BootstrapDialog.show({
title : 'Level 2 Title',
message: $('#lavel-2_div-4'),
onhide : function(){
$('#hidden-div').append(msg);
}
});
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.35.3/css/bootstrap-dialog.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.35.3/js/bootstrap-dialog.min.js"></script>
<!-- This is a container Div which contains all the div to show when bootstrap dialog opens -->
<div style="display : none" id="hidden-div">
<div id="simple-div">
<h1>This is H1 Heading</h1>
This is most simple coding
<br>
<button type="button" class="btn btn-primary" onclick="showDiv1()">Lavel-2 div-1</button>
<button type="button" class="btn btn-primary" onclick="showDiv2()">Lavel-2 div-2</button>
</div>
<div id="lavel-2_div-1">
<h3>This is Level 2 Header</h3>
<span style="color : blue;">This is Level 2 Message 1</span>
</div>
<div id="lavel-2_div-2">
<h3>This is Level 2 Header</h3>
<span style="color : greenyellow;">This is Level 2 Message 2</span>
</div>
<div id="lavel-2_div-3">
<h3>This is Level 2 Header</h3>
<span style="color : pink;">This is Level 2 Message 3</span>
</div>
<div id="lavel-2_div-4">
<h3>This is Level 2 Header</h3>
<span style="color : green;">This is Level 2 Message 4</span>
</div>
<div class="container-fluid" id="complex-div">
<button type="button" class="btn btn-primary" onclick="showDiv3()">Lavel-2 div-3</button>
<button type="button" class="btn btn-primary" onclick="showDiv4()">Lavel-2 div-4</button>
<h2>Panels with Contextual Classes</h2>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">Panel with panel-default class</div>
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Panel with panel-primary class</div>
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-success">
<div class="panel-heading">Panel with panel-success class</div>
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">Panel with panel-info class</div>
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">Panel with panel-warning class</div>
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-danger">
<div class="panel-heading">Panel with panel-danger class</div>
<div class="panel-body">Panel Content</div>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary" onclick="simpleSHow('Hello 1234')">Simple Div Show</button>
<button type="button" class="btn btn-primary" onclick="complexSHow('Complex 1234')">Complex Div Show</button>
I have a page that simplified, looks like this :
<html>
<form>
//form contents here
//modal 1 here
<div class="modal fade" id="addTime" tabindex="-1" role="dialog" aria-labelledby="addTimeLabel">
<div class="modal-content">
<div class="modal-header">
<div class="modal-body">
<div class="modal-footer">
</div></div></div>
</form>
// insert duplicate modals here (2 of them)
</html>
The modal within the form works perfect, but when I click on buttons to call up modals 2 and 3, they appear within the 1st modals window? How can I fix this?
Edit : If I delete the 1st modal entirely, 2 and 3 work perfect.... but I need the 1st modal too!
$(document).ready(function () {
$('#openBtn').click(function () {
$('#myModal').modal({
show: true
})
});
$(document).on('show.bs.modal', '.modal', function (event) {
var zIndex = 1040 + (10 * $('.modal:visible').length);
$(this).css('z-index', zIndex);
setTimeout(function() {
$('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
}, 0);
});
});
/* crazy batman newspaper spinny thing */
.rotate {
transform:rotate(180deg);
transition:all 0.5s;
}
.rotate.in {
transform:rotate(1800deg);
transition:all 1.5s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<h2>Stacked Bootstrap Modal Example.</h2>
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>
<div class="modal fade" id="myModal">
<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">Modal 1</h4>
</div>
<div class="container"></div>
<div class="modal-body">Content for the dialog / modal goes here.
<br>
<br>
<br>
<p>more content</p>
<br>
<br>
<br> <a data-toggle="modal" href="#myModal2" class="btn btn-primary">Launch modal</a>
</div>
<div class="modal-footer"> Close
Save changes
</div>
</div>
</div>
</div>
<div class="modal fade rotate" id="myModal2">
<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">Modal 2</h4>
</div>
<div class="container"></div>
<div class="modal-body">Content for the dialog / modal goes here.
<br>
<br>
<p>come content</p>
<br>
<br>
<br> <a data-toggle="modal" href="#myModal3" class="btn btn-primary">Launch modal</a>
</div>
<div class="modal-footer"> Close
Save changes
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal3">
<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">Modal 3</h4>
</div>
<div class="container"></div>
<div class="modal-body">Content for the dialog / modal goes here.
<br>
<br>
<br>
<br>
<br> <a data-toggle="modal" href="#myModal4" class="btn btn-primary">Launch modal</a>
</div>
<div class="modal-footer"> Close
Save changes
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal4">
<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">Modal 4</h4>
</div>
<div class="container"></div>
<div class="modal-body">Content for the dialog / modal goes here.</div>
<div class="modal-footer"> Close
Save changes
</div>
</div>
</div>
</div>
Check this jsfiddle:http://jsfiddle.net/CxdUQ/