HTML Tabs that are created using foreach - html

Im working on a a web page that has to have tabs. The tabs have to be created using a for each because the content has to be loaded out of a list. I found a tutorial on w3schools (https://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp). I tried to replicate on of the examples and added the foreach loop. But if i click one of the tabs, i get sent to the index.hmtl (probably because of the # in the href).I can neither change the model or the list.
<div class="container">
<ul class="nav nav-tabs">
#foreach (FooModel foo in fooModels)
{
<li class="nav-item">
<a class="nav-link active" href="#foo_#foo.Id">#foo.Title</a>
</li>
}
</ul>
</div>
<div class="card-body">
<h3>foo's</h3>
<div class="tab-content">
#foreach (FooModel fooModel in fooModels)
{
<div id="application_#fooModel.Id" class="tab-pane fade">
<h3>Foo:: #fooModel.Title</h3>
#if (IsInEditMode == true)
{
<InputDate #bind-Value="fooModel.DateFrom"></InputDate>
<InputDate #bind-Value="fooModel.DateTo"></InputDate>
}
else
{
<p>#fooModel.DateFrom.ToString()</p>
<p>#fooModel.DateTo.ToString()</p>
}
</div>
}
</div>
</div>

You forgot to include data-toggle="tab" inside <a class="nav-link active" href="#foo_#foo.Id">#foo.Title</a>. You then also need to remove the active inside it because it is inside a foreach loop. It should work if you add it.

Related

Adding custom CSS to the Wordpress Dashboard

I have a <li class="jobs-dashboard1"> I'd like to target with CSS. The problem is that it's not responding, so I wondered if it's possible to specify somehow with the id of the parent <ul> like so:
#adminmenu.jobs-dashboard1 {
background-color: green;
}
<div id="adminmenuback"></div>
<div id="adminmenuwrap">
<ul id="adminmenu">
<li class="wp-first-item wp-has-submenu wp-has-current-submenu wp-
menu-open menu-top menu-top-first menu-icon-dashboard menu-top.
first" id="menu-dashboard">
<a href='index.php' class="wp-first-item
wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-
top-first menu-icon-dashboard menu-top-first">
<div class="wp-menu-
arrow">
<div></div>
</div>
<div class='wp-menu-image dashicons-before
dashicons-dashboard'><br /></div>
<div class='wp-menu-
name'>Dashboard</div>
</a>
<ul class='wp-submenu wp-submenu-wrap'>
<li class='wp-submenu-head' aria-hidden='true'>Dashboard</li>
<li class="wp-first-item current">.
Home</li>
<li><a href='update-core.php'>Updates
<span class='update-plugins count-37'><span class='update.
count'>37</span></span></a></li>
<li class="jobs-dashboard1"><a href='https://adsler.co.uk/jobs-dashboard/' class="jobs.
dashboard1">Jobs</a></li>
<li class="post-job1"><a href='https://adsler.co.uk/post-a-job/' class="post-job1">Post A
Job</a></li>
<li class="events-dashboard1"><a href='https://adsler.co.uk/your-events-dashboard/' class="events.
dashboard1">Events</a></li>
<li class="post-event1"><a href='https://adsler.co.uk/post-an-event/' class="post-event1">Post
An Event</a></li>
</ul>
</li>
This didn't work, and I don't know why.
If you see Jobs in the screenshot... that's one of them I'm trying to target.
The site is https://adsler.co.uk if that helps, but it's a backend modification.
Where are you adding this CSS? You cannot add it to typical CSS files that you use on your website, because those are all loaded on the Frontend, and not loaded in the Wordpress Dashboard.
You also shouldn't have to target your item with an ID before the class, if the item has its own class already, and is only used on that item. If you use this class on more than one item then you can specify an ID or other selector.
Add this to the end your functions.php or a custom plugin
Here is the original posted solution:
add_action('admin_head', 'custom_admin_css');
function custom_admin_css() {
echo '<style>
.jobs-dashboard1 {background: green;}
</style>';
}
Here is another way that should also work.
add_action( 'admin_head', 'custom_admin_css' );
function custom_admin_css() { ?>
<style>
.jobs-dashboard1 {background-color: green; }
</style>
<?php }
Well, you have missed a space in your CSS declaration.
it should be,
#adminmenu .jobs-dashboard1 {background-color: green;}
Hope this helps!
It is because you have more layers of nodes over the ".jobs-dashboard1". So you could use this:
#adminmenu #menu-dashboard .wp-submenu .jobs-dashboard1{background-color: green;}
or if you want a cleaner way:
#adminmenu li ul .jobs-dashboard1{background-color: green;}
It works, Please check the below snippet. Also check CSS Combinators
#adminmenu .jobs-dashboard1 {
background-color: green;
}
<div id="adminmenuback"></div>
<div id="adminmenuwrap">
<ul id="adminmenu">
<li class="wp-first-item wp-has-submenu wp-has-current-submenu wp-
menu-open menu-top menu-top-first menu-icon-dashboard menu-top.
first" id="menu-dashboard">
<a href='index.php' class="wp-first-item
wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-
top-first menu-icon-dashboard menu-top-first">
<div class="wp-menu-
arrow">
<div></div>
</div>
<div class='wp-menu-image dashicons-before
dashicons-dashboard'><br /></div>
<div class='wp-menu-
name'>Dashboard</div>
</a>
<ul class='wp-submenu wp-submenu-wrap'>
<li class='wp-submenu-head' aria-hidden='true'>Dashboard</li>
<li class="wp-first-item current">.
Home</li>
<li><a href='update-core.php'>Updates
<span class='update-plugins count-37'><span class='update.
count'>37</span></span></a></li>
<li class="jobs-dashboard1"><a href='https://adsler.co.uk/jobs-dashboard/' class="jobs.
dashboard1">Jobs</a></li>
<li class="post-job1"><a href='https://adsler.co.uk/post-a-job/' class="post-job1">Post A
Job</a></li>
<li class="events-dashboard1"><a href='https://adsler.co.uk/your-events-dashboard/' class="events.
dashboard1">Events</a></li>
<li class="post-event1"><a href='https://adsler.co.uk/post-an-event/' class="post-event1">Post
An Event</a></li>
</ul>
</li>

Multiple independent sets of navigation tabs without multiple scripts to take care of hiding contents on clicks

In a previous question, I asked how to achieve something like this:
Where clicking any tab would reveal the contents of said tab and keep those of other tabs hidden. #BradleyCoupland suggested the following code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="text-align: justify">[Introduction text]</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler" id="defaultOpen" onclick="openPage('Vspoiler')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler" onclick="openPage('Cspoiler')">Campbell version</a></li>
</ul>
<div id="Vspoiler" class="tab-pane tabcontent active">
<br>
<table>
<tbody>
<tr>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 1 of tab 1]
</div>
</td>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 2 of tab 2]
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="Cspoiler" class="tab-pane tabcontent">
<br>
<table>
<tbody>
<tr>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 1 of tab 2]
</div>
</td>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 2 of tab 2]
</div>
</td>
</tr>
</tbody>
</table>
</div>
<script>
function openPage(pageName) {
var i, tabcontent;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
document.getElementById(pageName).style.display = "block";
}
document.getElementById("defaultOpen").click();
</script>
And it worked like a charm. But suppose I now want to do multiple independent sets of tabs, like this:
I tried just copy-pasting the <ul> part twice, and the result was that the second set of tabs showed nothing on loading, and clicking on a tab in any tab set would do the right thing in its set, but hide all the tabs of the other set as well. For example, clicking on "weird-meter older reconstruction" would show what you see in the image for that tab, but hide the contents of the "P.Oxy. version" tab below. Simplifying the code above to a minimal example:
<div style="text-align: justify">Intro</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler" id="defaultOpen" onclick="openPage('Vspoiler')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler" onclick="openPage('Cspoiler')">Campbell version</a></li>
</ul>
<div id="Vspoiler" class="tab-pane tabcontent"><br>
Pefanthi
</div>
<div id="Cspoiler" class="tab-pane tabcontent"><br>
Abanthi
</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler2" id="defaultOpen" onclick="openPage('Vspoiler2')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler2" onclick="openPage('Cspoiler2')">Campbell version</a></li>
</ul>
<div id="Vspoiler2" class="tab-pane tabcontent"><br>
Pefanthi
</div>
<div id="Cspoiler2" class="tab-pane tabcontent"><br>
Abanthi
</div>
<br>
<br>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function openPage(pageName) {
var i, tabcontent;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
document.getElementById(pageName).style.display = "block";
}
document.getElementById("defaultOpen").click();
</script>
Which loads to this:
And where clicking the lower "Vulgate version" tab produces this:
Now the obvious solution to this problem is to duplicate the script, by making an otherwise identical function openPage2 which appends a 2 to everything it works with, and then use openPage2, tabcontent2 and defaultOpen2 for the second set of tabs and the no-2 versions for the first one. Now suppose you have more than 2 sets. Say you have 10. 10 scripts? Surely there must be a less clumsy way of fixing this problem? I was thinking maybe one could set a variable to store the number of tabs and then make a script with a for loop that would result in running all the openPage<x> scripts at the right time by writing a single script, but I'm not sure how to go about this.
Any suggestions?
You don't need to use javascript to close/toggle the nav-tabs, bootstrap has this functionality built in. The reason why it's not working out of the box is because there are a few things missing in the html. You need to wrap all the tab content inside a div with class="tab-content" as shown below:
<ul class="nav nav-tabs">
<!-- add data-toggle attribute to the anchors -->
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content"> <!-- wrapper for all tab content -->
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
Here is a live demo stacking two of the snippets above:
https://www.bootply.com/WuuHKy9jwR

AngularJS ng-class and invalid tab - functionality is broken

We have tabs working correctly using this HTML
<div class="col-lg-3 col-md-3 panel-container">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a data-toggle="pill" href="#general" ng-class="{true: 'invalid-tab', false: ''}[form.editTemplateGeneralForm.$invalid]">#Labels.general</a></li>
<li><a data-toggle="pill" href="#startingValues" ng-class="{true: 'invalid-tab', false: ''}[form.editTemplateStartingValuesForm.$invalid]">#Labels.startingValues</a></li>
</ul>
</div>
The invalid-tab used to work fine, and when the tab was invalid it was shown in red. Now it's no longer working and we suspect it's the newest version of AngularJS that broke that functionality. We're using v1.3.13.
Do you know what should be adjusted in that syntax above to make it work again (that is used in many pages of our application).
Here is the invalid-tab from our site.css:
.widget .invalid-tab * {
background-color: #F9EAF3;
/*color: #F9EAF3;*/
color: #d43f3a;
}
.widget .invalid-tab:hover * {
background-color: #E06B6C;
color: #ffffff;
}
The correct way to define ng-class is as follows: ng-class="{classname: expresstion}"
You also need to remove the asterisk from the css-selector - as you are selecting any child element. But the .invalid-tab has no child elements.
Another solution would be to move the .invalid-tab class out to the parent li-element
angular.module('myApp', [])
.directive('testApp', function(){
return {
link: function(scope) {
scope.form = {
editTemplateStartingValuesForm: {$invalid: true},
editTemplateGeneralForm: {$invalid: false}
};
}
};
});
.widget .invalid-tab {
background-color: #F9EAF3;
/*color: #F9EAF3;*/
color: #d43f3a;
}
.widget .invalid-tab:hover {
background-color: #E06B6C;
color: #ffffff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<div ng-app="myApp" class="widget" test-app>
<div class="col-lg-3 col-md-3 panel-container">
<ul class="nav nav-pills nav-stacked">
<li class="active">
<a data-toggle="pill" href="#general" ng-class="{'invalid-tab': form.editTemplateGeneralForm.$invalid}">#Labels.general</a>
</li>
<li>
<a data-toggle="pill" href="#startingValues" ng-class="{'invalid-tab': form.editTemplateStartingValuesForm.$invalid}">#Labels.startingValues</a>
</li>
</ul>
</div>
</div>

URL pathway is wrong

I'm working on a project were I want to add top links to the masterPage and each top-link to have its own navigation like this:
What I did was to include the top-links directly under the Content
The problem with this however, is that the URL pathway is wrong when selecting a menu under non-HomePage link
For example if I select For skolpersonal as a top-link and then select a menu and then a submenu, the URL pathway would be: menu/submenu
What I want it to be is: for-skolpersonal/menu/submenu
For some reason the URL "resets" every time I select a menu under a top-link.
MasterPage:
<header>
<div class="row col-md-12">
<nav class="entry-links">
<ul>
<li id="elever">
För elever
</li>
<li id="skolpersonal">
För skolpersonal
</li>
<li id="ungdom">
Ungdom och elevdatabas
</li>
</ul>
</nav>
</div>
<div class="row">
<div class="col-xs-8 col-sm-12 col-md-4">
<a href="#home.Url">
<div class="brand" style="background-image:url('#(home.SiteLogo)?height=100&width=700&')"></div>
</a>
</div>
</div>
<div class="row">
<div class="col-md-12 main-nav">
<nav id="cbp-hrmenu" class="meny cbp-hrmenu col-md-10 col-md-offset-1">
#{ Html.RenderPartial("MainNavigation"); }
</nav>
</div>
<br />
<br />
</div>
<div class="container-fluid">
<div class="container">
</div>
</div>
<div id="toggle" class="toggle">
<span></span>
</div>
</header>
MainNavigation:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{ var home = CurrentPage.Site(); }
#if (home.Children.Any())
{
#* Get the first page in the children *#
var naviLevel = home.Children.First().Level;
#* Add in level for a CSS hook *#
<div class="linje"></div>
<ul class="meny level-#naviLevel">
#* For each child page under the home node *#
#foreach (var childPage in home.Children)
{
if (childPage.Children.Any())
{
<li class="dropdown has-child #(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
#if (childPage.DocumentTypeAlias == "Huvudmeny")
{
<span>#childPage.Name</span>
#childPages(childPage.Children)
}
else
{
#childPage.Name
}
#helper childPages(dynamic pages)
{
#* Ensure that we have a collection of pages *#
if (pages.Any())
{
#* Get the first page in pages and get the level *#
var naviLevel = pages.First().Level;
#* Add in level for a CSS hook *#
<ul class="meny dropdown-menu sublevel level-#(naviLevel)">
#foreach (var page in pages)
{
<li>
#page.Name
#* if the current page has any children *#
#if (page.Children.Any())
{
#* Call our helper to display the children *#
#childPages(page.Children)
}
</li>
}
</ul>
}
}
</li>
}
else
{
<li class="#(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
#childPage.Name
</li>
}
}
</ul>
<div class="linje col-md-12" ></div>
}
Is there a way to make the URL pathway to go as I want them to? topmenu/menu/submenu
I'm using Umbraco.
To include top level nodes in the path go to your web.config file and change the value of the umbracoHideTopLevelNodeFromPath app setting from true to false.

show different images after click on different li (as a second menu)

This is my html as a second menu in a page.
<ul class="nav-tabs text-center" role="tablist">
<li class="active">Lunch</li>
<li class="diner">Diner</li>
<li class="pannenkoek">Pannenkoek</li>
<li class="borrel">Borrel</li>
</ul>
Now when i want to click on a li there has to show an image. When you click on the second link there has to show another image. The problem now is when i click on a link, it doesn't matter which one, it shows al the images on the page of all the divs.
<div class="active"><img src="images/themenu/lunchkaart-november.jpg" alt="lunchkaart" /> </div>
<div class="diner"><img src="images/themenu/dinerkaart-januari.jpg" alt="dinerkaart" /> </div>
How te create when click on li lunch, it show image lunch.
When click on li diner, it show image diner.
What did i do wrong?
You need jQuery for that. Use this or maybe add class active for clicked element div. Also active class most be display:block or display:inline-block;
<ul class="nav-tabs text-center" role="tablist">
<li class="lunch">Lunch</li>
<li class="diner">Diner</li>
<li class="pannenkoek">Pannenkoek</li>
<li class="borrel">Borrel</li>
</ul>
<div class="content">
<div class="lunch" style="display:none"><img src="images/themenu/lunchkaart-november.jpg" alt="lunchkaart" /> </div>
<div class="diner" style="display:none"><img src="images/themenu/dinerkaart-januari.jpg" alt="dinerkaart" /> </div>
</div>
jQuery(document).ready(function(){
jQuery('.nav-tabs li').click(function(){
var elementClass = jQuery(this).attr("class").toString();
console.log(elementClass);
jQuery('.content div').hide();
jQuery('.'+elementClass,'.content').show();
});
});
http://jsfiddle.net/e79g4p1p/14/