Remove ACTIVE class from nav-link element in Bootstrap 4 - php

I need to remove the ACTIVE class from nav-item when the user closes the tab. I try to build tabs with text content inside. Tabs should be closed by default when the user opens the page. When the user clicks on a tab to open it, it should change the color to blue (So here I can use the active class to add style), but when it closes, it should change the color to white. The best way would be to remove the ACTIVE class from li and I stuck here. How to do it? Unfortunately Bootstrap does not remove the ACTIVE class when I click on the tab to close it. Bootstrap removes the ACTIVE class only when I switch between tabs.
Here is my HTML:
<div class="col-md-12">
<ul class="nav nav-tabs justify-content-center" role="tablist">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#one" role="tab">One</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#two" role="tab">Two</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#three" role="tab">Three</a>
</li>
</ul>
<div class="tab-content">
<div class="text-center tab-pane" id="one" role="tabpanel">1 tab content</div>
<div class="text-center tab-pane" id="two" role="tabpanel">2 tab Content</div>
<div class="text-center tab-pane" id="three" role="tabpanel">3 tab content</div>
</div>
</div>
And here is my JS:
jQuery(function ($) {
$(".nav-link").click(function(){
if ($(this).hasClass('active')){
$('#' + this.hash.substr(1).toLowerCase()).toggleClass('active');
}
});
});

Just go over all the nav-item's and remove the class when the user closes the tab
$('.your-close-icon').on('click', function() {
$('.nav-item').removeClass('active');
});

Related

Boostrap 4 menu dropdown not showing completely using it in include

I made a menu with bootstrap and php. It works fine but when I use it with an include in another php file the dropdown items are not seen. I don't know if I'm missing a div or should I use something else?
this is my menu.php code:
<body>
<nav class="navbar navbar-expand-sm bg-secondary navbar-dark sticky-top">
<ul class="navbar-nav">
<!-- Brand/logo -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">Administracion</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="ajuste.php">Ajuste Cota</a>
<a class="dropdown-item" href="estaciones.php">Estaciones</a>
<a class="dropdown-item" href="panel.php">Panel de Control</a>
<a class="dropdown-item" href="permisos.php">Permisos</a></div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">Medicion</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="">Puesto 1</a>
<a class="dropdown-item" href="">Puesto 2</a>
<a class="dropdown-item" href="">Puesto 3</a>
</div>
</li>
</ul>
</nav>
</body>
and this is how I use this in another php file
<body>
<?php include("menu.php");?>
<br>
<div class="container">
.
.
.
</body>
I should see the menu as follows:
menu.php:
But when I use menu.php in other file (as include) the menu item does not diplay
menu.php used as include file:
Can someone guide me how to fix this?
Too many <body> tags...you should only have one set (<body>...</body>) in your whole page. You don't need them in the menu file if that's going to be included in another file.

Is it possible to refresh a tab on click - Bootstrap tabs

I've created two tabs, using PHP tab one is made to insert data to database and another to view the data from the database, someone suggested ajax, but i couldn't find the answer i want.
example code -
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu1">Menu 1</a>
</li>
</ul>
<div class="tab-content">
<div id="home" class="container tab-pane active">
<?php require("insert.php"); ?>
</div>
<div id="menu1" class="container tab-pane fade">
<?php require("view.php"); ?>
</div>
</div>
at tab one, i insert data (PHP) and tab two i view the data in table (PHP), so after inserting, i have to refresh the whole page to view the updated data on tab two.
So is it possible to refresh tab two right after i insert data on tab two, so i can view updated data without refreshing the whole page? if this is already solved, please comment answer links.
It may seem crude, but i made it work using JavaScript.
$(document).ready(function(){
$(".t1").load("insert.php");
$(".t2").load("view.php");
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
var target = $(e.target).attr("href") // activated tab
if(target=='#home')
{
$(".t1").load("insert.php");
}
else if(target=='#profile')
{
$(".t2").load("view.php");
}
});
});
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#profile">Menu 1</a>
</li>
</ul>
<div class="tab-content">
<div id="home" class="container tab-pane active t1">
</div>
<div id="profile" class="container tab-pane fade t2">
</div>
</div>

How to add an action in a nav-link in php

I've a project where i need to use the MVC2 architecture. So far so good, but I'm stuck with the navigation bar.
Basically, I'm making a webpage where I have a navigation bar with different options available. When I click in one of the options, I want an "action" to be made, which would be sent to an Action Builder Class which would generate a view with the specific page.
For instance, this is my ActionBuilder class, which is in my Controler folder
<?php
require_once('./controleur/DefaultAction.class.php');
require_once('./controleur/MenuAction.class.php');
require_once('./controleur/LogginAction.class.php');
require_once('./controleur/ContactAction.class.php');
class ActionBuilder{
public static function getAction($nomAction){
switch ($nomAction)
{
case "Menu" :
return new MenuAction();
break;
case "Tarification" :
return new TarificationAction();
break;
case "Contact" :
return new ContactAction();
break;
default :
return new DefaultAction();
}
}
}
?>
Here is my css:
<form method="post" action="">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="navbar-collapse collapse show" id="navbarColor01" style="">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#" id="APropos">À propos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" id="Tarification">Tarif</a>
</li>
<li class="nav-item">
<a class="nav-link" href="MenuOffert.php">Menus offert</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" id="Contact">Nous contacter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Loggin.PHP">Se connecter</a>
</li>
</ul>
</div>
</nav>
After we clicked, for example Contacter in the navigation bar, what I need is to send an action to the controler which would call this ContactAction class:
<?php
require_once('./controleur/Action.interface.php');
class ContactAction implements Action {
public function execute(){
return "Contact";
}
}
which eventually would show the page with the info that I need.
How can I do this?
Also, do I have to set a form in the navigation bar as I did? I'm really not sure for that part.
Thank you.
add your url where you want to display the page to your navigation.
example: À propos
edit the href="#" to href="<?php echo base_url('index.php/add/your/link')"

How to update content in Bootstrap tabpanel

this is my first question in this site and I need some help.
I am creating a socialnetwork , facebook like style and I have a tabpanel with 2 tabs in bootstrap, the fist tab is "Friends", where the content of friends will be shown, and the second tab not so important as the fist one is called "Home" where all posts from the user will be placed.
In the first tab , I need to reload the content dinamically, by clicking this tab all new posts from friends must appear. (I have already done this).
It works now by refreshing all page, or F5. But I dont know how to do all this.
if code help, I paste here the html code:
<li role="presentation" class="active">
<a data-toggle="tab" role="tab" aria-controls="friends" href="#friends">
<i class="fa fa-user">
Friends
</i>
</a>
</li>
<li role="presentation">
<a data-toggle="tab" role="tab" aria-controls="home" href="#home">
<i class="fa fa-home">
Home
</i>
</a>
</li>
</ul>
<div class="tab-content">
<div id="friends" class="tab-pane active" role="tabpanel">
<p>
Friends
</p>
<p>
<?php ListFPosts($id_user);?>
</p>
</div>
<div id="home" class="tab-pane active" role="tabpanel">
<p>
Home
</p>
<p>
<?php ListMyPosts($id_user);?>
</p>
</div>
</div>
</div>
I've read a lot of, and I think I need Ajax and I dont know this language yet, someone could help me?.
Some help please?
Thx in advance.

How do I keep the current tab active?

I use bootstrap theme bs-admin-bcore and I want to make menu in file "menu.php" to be more dynamic.
For example, I have this code :
<ul id="menu" class="collapse">
<li class="panel">
<a href="index.php" >
<i class="icon-table"></i> Dashboard
</a>
</li>
<li class="panel ">
<a href="#" data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav">
<i class="icon-tasks"> </i> UI Elements<span class="pull-right"><i class="icon-angle-left"></i></span> <span class="label label-default">10</span>
</a>
<ul class="collapse" id="component-nav">
<li class=""><i class="icon-angle-right"></i> Buttons </li>
</ul>
</li>
</ul>
when I call index.php <li class="panel"> becomes <li class="panel active"> and when I call button.php EU Elements becomes active.
You have to add "active" class to the parent li of buttons as well n it will work.

Categories