Im using a loop to render a <div> with tabs in it for each item in a list:
#foreach (var item in Model.things)
{
int counts = 1;
<div class="col-md-12">
<!-- BOX -->
<div class="box border red">
<div class="box-title">
<h4><i class="fa fa-columns"></i><span class="hidden-inline-mobile">#item.Name</span></h4>
</div>
<div class="box-body">
<div class="tabbable header-tabs">
<ul class="nav nav-tabs">
<li class=""><i class="fa fa-circle-o"></i> <span class="hidden-inline-mobile">More</span></li>
<li class=""><i class="fa fa-laptop"></i> <span class="hidden-inline-mobile">Profile</span></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="box_tab1">
<p>Content #1</p>
<p>...</p>
</div>
<div class="tab-pane fade" id="box_tab2">
<p>Content #2</p>
<p>...</p>
</div>
</div>
</div>
</div>
</div>
<!-- /BOX -->
</div>
}
The problem here is the harcoded values in for example:
<a href="#box_tab2> that "opens" the tab id="box_tab2".
Of course this does not work when there are several tabs with the same ids.
Can I maybe use an index in order to be able to assign unique values where needed?
You're on the right way using a counter/index, you have to use it to build your IDs, in your nav-tabs:
<li><a href='#String.Format("#box_tab1_{0}", count)'>
<li><a href='#String.Format("#box_tab2_{0}", count)'>
and in your tab-content:
<div class="tab-pane fade" id='#String.Format("box_tab1_{0}", count)'>
<div class="tab-pane fade" id='#String.Format("box_tab2_{0}", count++)'>
Note count++ to increment counter after last usage in each loop iteration.
Related
This is my block of code , I want to redirect to a href tab using the # when I click the Next button. Now my code when I click the next button only send me on the Index #. I know this work with Jquery or Ajax... but I do not know how to implement that. That why I'm looking for help. Thanks.
<div class="row" >
<div class="col-lg offset-1 col-lg-10 col-md-12 col-xs-12 col-sm-12">
<div id="wizard" class="adjust" >
<div class="navbar-inner" >
<div class = "container" style="visibility:hidden;" >
<ul>
<li> First</li>
<li> Second</li>
<li> Third</li>
</ul>
</div>
</div>
</div>
<div class="tab-content" >
<div class="tab-pane" id="tab1" >
#Html.Partial("PartialHome_Main")
</div>
<div class="tab-pane" id="tab2" >
#Html.Partial("PartialPage_Main")
</div>
<div class="tab-pane" id="tab3" >
#Html.Partial("PartialP_Main")
</div>
</div>
<div class="row" >
<div id="nextBtn" class="col-xs-12 col-md-12 col-sm-12 col-lg-12 text-center" >
<a class =" next btn2 btn2-primary FinishBtn" href="#" > next <i class="fa fa chevron-right" ></i> </a>
I'm working on a Spring-Boot application using Thymeleaf. Bootstrap4 is the CSS framework I'm using. I'm using nav-tabs for the profile page and the first three tabs don't have any issues but when I click on the address tab and go to any other tab, the content of the Address tab, shows up in the other tabs at the bottom of that tabs content and I cannot figure out why. I'll be including images of the outcome and css of each starting tab. I am hesitant to include the entire page html due to the amount of lines currently (480 total)
<div class="tab-pane fade" id="tab-3" role="tabpanel" th:classappend="${classActiveBilling}? 'in active show'">
<div class="card">
<div class="card-body">
<div class="card-title">
<div class="container">
<div class="row">
<div class="col">
<h4 class="mb-0 align-middle" style="margin-top: 15px;">Billing Information</h4>
</div>
</div>
<div class="row">
<div class="col">
<div class="breadcrumb" style="background-color:transparent;">
<a class="breadcrumb-item active" th:href="#{/listOfCreditCards}" th:style="${listOfCreditCards}? 'color:#6e45e0'">List of Credit Cards</a>
<a class="breadcrumb-item active" th:href="#{/addNewCreditCard}" th:style="${addNewCreditCard}? 'color:#6e45e0'">Add/Update Credit Card</a>
</div>
</div>
</div>
<div class="tab-pane fade" id="tab-4" role="tabpanel" th:classappend="${classActiveShipping}? 'in active show'">
<div class="card">
<div class="card-body">
<div class="card-title">
<div class="container">
<div class="row">
<div class="col">
<h4 class="mb-0 align-middle" style="margin-top: 15px;">Shipping Information</h4>
</div>
</div>
<div class="row">
<div class="col">
<div class="breadcrumb" style="background-color:transparent;">
<a class="breadcrumb-item active" th:href="#{/listOfShippingAddresses}" th:style="${listOfShippingAddresses}? 'color:#6e45e0'">List of Shipping Addresses</a>
<a class="breadcrumb-item active" th:href="#{/addNewShippingAddress}" th:style="${addNewShippingAddress}? 'color:#6e45e0'">Add/Update Shipping Address</a>
</div>
</div>
</div>
The breadcrumbs were the culprit. It was causing the shipping tab to show up in other windows. I just changed it to a button group and get the same effect. I unfortunately could not get the breadcrumbs themselves to work regardless of how many times I worked on the css so just threw it out completely. Semi answer, but thymeleaf is touchy and doesn't always play nice with frameworks.
On initial load, the content from both tabs show on the webpage, once the tab is clicked for the first time they begin to work as expected.
Any ideas on why this is happening?
Here is my html
<div id="userFunctions" style="display: none;" >
<h2 id="welcome"></h2>
<button id="btnChangeUser" class="btn btn-primary" style="display: none;">Change User</button>
<br>
<hr>
<ul class="nav nav-tabs">
<li class="active"><a id="showSubs" data-toggle="tab" href="#subscriptionManagement">Subscription Portal</a></li>
<li><a id="showLocation" data-toggle="tab" href="#locationManagement">Location Management</a></li>
</ul>
<div class = tab-content>
<div id="subscriptionManagement" class="tab-pane fade in active">
<hr>
<section id="sendSubRequest">
<h4>Request Subscription</h4>
<div class="input-group">
<input type="text" id="subUserName" class="form-control "></input>
<span class="input-group-btn">
<button id="btnSubUser" class="btn btn-primary">Subscribe</button>
</span>
</div>
</section>
<br>
<section id="ReviewSubRequests">
<h4>Incoming Request(s)</h4>
<ul id='subscriptionsList'>
</ul>
</section>
</div>
<div id="locationManagement" class="tab-pane fade in active">
<hr>
<section id="cityDetails">
<section id="map">
</section>
<br>
<section>
<button id="btncheckInLocation" class="btn btn-primary">Check-In User location</button>
</section>
</section>
<section id="friendsList">
<h4>Subscribed Friends</h4>
<ul id='subscribedUsers'>
</ul>
</section>
</div>
</div>
</div>
Both your tabs (#subscriptionManagement and #locationManagement) have the active class, meaning they are both active by default. This class should be getting added on navigation, indicating that the content should be shown. You simply need to remove this class from the tab which you don't want to show on initial load:
Change:
<div id="locationManagement" class="tab-pane fade in active">
To:
<div id="locationManagement" class="tab-pane fade in">
Hope this helps! :)
My website contains this simple menu home, about me and contact.
It's single page website, I want to make it easy for user's when visiting my page, user can scroll down the page to check the contact or about me etc or user can just simply click About me or Contact and the window will pop up and show only About me or Contact [using modals in bootstrap], I am able to do that ,but all things event containing modals are hidden on my page , how can I make those things containing modals visible on my page ?
Here is simple contact page codes with modals.
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav" id="nav">
<li>
<a href="#">Home
</a>
</li>
<li>
<a href="#abt_modal" data-toggle="modal" data-target="#abt_modal">About me
</a>
</li>
<li>
<a href="#modal1" data-toggle="modal" data-target="#myModal"> Contact
</a>
</li>
<li>
</ul>
</div>
<div id="myModal" class="modal" role="dialog">
<div class="modal-dialog">
<footer class="f7" id="modal1">
<button type="button" class="btn btn-default" data-dismiss="modal" id="close1">Close</button>
<div class="container-fluid">
<div class="row" id="ft">
<div class="ft">
<h3> SAY HELLO </h3>
<span>get in touch</span>
</div>
<div class="col-md-4 a">
<p>
<i class="fa fa-mobile-phone fa-5x"></i> <br><br>
<span> Call us at </span><br>
<span> +467i7292518347</span><br>
</p>
</div>
<div class="col-md-4 a" >
<p>
<i class="fa fa-map-marker fa-5x"></i> <br><br>
<span> Ul.Zagórze 27A </span> <br>
<span>05-098 Sadowata,<br> Poland </span>
</p>
</div>
<div class="col-md-4 a">
<p>
<i class="fa fa-envelope fa-5x"></i><br><br>
<span> Email us at</span> <br>
<span>Hotbong20376gównoJebanye#gmail.com</span><br>
</p>
</div>
</div>
</div>
</footer>
</div>
</div>
Copy pest code in individual file and check in your local it will run. perfect. Given below is modern way of doing it. You can refer this link for further details of the way of creating modal dynamically.
function openModalDynamic() {
var message = $('#content-div');
BootstrapDialog.show({
title: 'Default Title',
message: $('#content-div'),
buttons: [{
label: 'Close',
action: function(dialog) {
dialog.close();
}
}],
onhide: function(dialog) {
$('#content-container').append(message);
}
});
};
function openModalDynamic2() {
BootstrapDialog.show({
title: 'Default Title',
message: $('#content-div').clone(true),
buttons: [{
label: 'Close',
action: function(dialog) {
dialog.close();
}
}],
onhide: function(dialog) {}
});
}
<!DOCTYPE html>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/css/bootstrap-dialog.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<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.34.7/js/bootstrap-dialog.min.js"></script>
<button type="button" onclick="openModalDynamic()">Type 1</button>
<button type="button" onclick="openModalDynamic2()">Type 2</button>
<br> Type 1 : This code will cut the div from original location and put it into your modal.<br> Type 2 : This code will copy the div from original location and put it into your modal. So you will see same div at both the place.<br> This will work great
until and unless you have any activity depending upon id's of elements.
<div style="height : 250px">
</div>
<div id="content-container">
<div id="content-div">
<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 class="row">
<div class="col-sm-6">
About US will go here.
</div>
<div class="col-sm-6">
Contact US will go here.
</div>
</div>
</div>
</div>
</div>
I'm trying to implement a html tabbed interface. For some reason clicking on a tab will kick me back to the homepage instead of showing a new list of data. Do I need to add a url route to the <a href> ?
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Overview</li>
<li role="presentation">Documents</li>
<li role="presentation">List</li>
</ul>
<div id="mainBody">
<div class="tab-content">
<div class="tab-pane active" id="overview">
<div role="tabpanel">
DATA 1
</div>
</div>
<div class="tab-pane" id="documents">
<div role="tabpanel">
DATA 2
</div>
</div>
<div class="tab-pane" id="punchlist">
<div role="tabpanel">
DATA 3
</div>
</div>
</div>
</div>
If you mean you are just trying to show the contents of the tab then I would change your href="#something" to href="javascript: return false;" or put the code in your event handler.
Tested this over on Bootply
http://www.bootply.com/DqUJfu6r4z
You simply need to close the quotations on your IDs:
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Overview</li>
<li role="presentation">Documents</li>
<li role="presentation">List</li>
</ul>
<div id="mainBody">
<div class="tab-content">
<div class="tab-pane active" id="overview">
<div role="tabpanel">
DATA 1
</div>
</div>
<div class="tab-pane" id="documents">
<div role="tabpanel">
DATA 2
</div>
</div>
<div class="tab-pane" id="punchlist">
<div role="tabpanel">
DATA 3
</div>
</div>
</div>
</div>