Topic: Tab content remaining active + text input label mis-aligned
tblfounder pro asked 7 years ago
Hi,
I have recently upgraded from 4.3.2 to 4.4.1 and I have a new and pressing issue with tabs. Tab content is still remaining 'active' after a different tab is selected. The old tab content is shown under the new tab content. The very first text input in the original tab also has its label incorrectly positioned over the text field.
This appears to be associated with the text input and associated label being present in the tab content and only occurs if the text input has an initial value set and a label.
The minimal code below shows the problem.
Be grateful for any solutions to this.
Regards
Ben
<html> <head> <script src="/js/jquery-3.2.1.min.js" type="text/javascript"></script> <link href="/css/bootstrap.css" rel="stylesheet"> <link href="/css/mdb.css" rel="stylesheet"> </head> <body> <main> <form> <ul class="nav nav-tabs md-pills pills-ins" role="tablist"> <li class="nav-item"> <a id="general-tab" class="nav-link active" data-toggle="tab" href="#first-panel" role="tab">First</a> </li> <li class="nav-item"> <a id="uas-tab" class="nav-link" data-toggle="tab" href="#second-panel" role="tab">Second</a> </li> </ul> <div class="tab-content"> <div class="tab-pane active show" id="first-panel" role="tabpanel"> <p>First tab contents</p> <div class="md-form"> <input type="text" name="password" id="password" class="form-control" value="123"> <label for="password">Password</label> </div> </div> <div class="tab-pane" id="second-panel" role="tabpanel"> <p>Second Tab Contents</p> </div> </div> </form> </main> <script type="text/javascript" src="/js/popper.min.js"></script> <script type="text/javascript" src="/js/bootstrap.js"></script> <script type="text/javascript" src="/js/mdb.js"></script> </body> </html>
Ryan Ternier free answered 7 years ago
We use Tabs to make large forms easier to fill out rather than have multiple forms. Now, it's possible to use multiple forms, and work around that (if your architecture allows for such), but you shouldn't force people to use multiple forms as some languages/frameworks won't work well with it.
I should add, using multiple tabs with one <form> inside each tab you will still see this issue.
Is there a fix coming?
tblfounder pro answered 7 years ago
Mirosław Stasiak free answered 7 years ago
Hi,
You can not do a form that has both tabs.
This is the solution for the labels:
if($('#password').val() || $('#password').attr('placeholder')) { if(!$('#password').siblings('label').hasClass('active')) { $('#password').siblings('label').addClass('active'); } }
https://codepen.io/mirekmts/pen/aLbQgZ
Regards,
tblfounder pro answered 7 years ago
Mirosław Stasiak free answered 7 years ago
SOLUTION
Check the solution written on codepen.io
Don't look at styles because this is MDB Free version
https://codepen.io/mirekmts/pen/aLbQgZ
Edit:
I'm going to write a solution with an incorrect label show when the text is inside.
I focused on tabs and missed the labels
Edit 2:
In codepen.io you have got a working solution (tabs and input)
tblfounder pro answered 7 years ago
Hi Miroslav,
Here are the tab-content panel classes on each tab press with your script:
Initial:
first-panel: tab-pane fade in show active second-panel: tab-pane fade
After pressing Second:
first-panel: tab-pane fade in show second-panel: tab-pane active
After pressing First:
first-panel: tab-pane in show active second-panel: tab-pane
Regards
Ben
tblfounder pro answered 7 years ago
Mirosław Stasiak free answered 7 years ago
<script> $('a[data-toggle="tab"]').on('show.bs.tab', function (e) { var href = e.relatedTarget.getAttribute("href"); if($(href).hasClass('active')) { $(href).removeClass('active'); } }); </script>
tblfounder pro answered 7 years ago
tblfounder pro answered 7 years ago
Mirosław Stasiak free commented 7 years ago
The code I sent you above works fine. Check that you have some bugs in the console and that all CSS files are loaded correctly.Mirosław Stasiak free answered 7 years ago
Hi,
You have got a few bugs in your code.
Why would you want all tabs to be in form, not just where you have input?
You forgot to add a fade class.
<ul class="nav nav-tabs md-pills pills-ins" role="tablist"> <li class="nav-item"> <a id="general-tab" class="nav-link active" data-toggle="tab" href="#first-panel" role="tab">First</a> </li> <li class="nav-item"> <a id="uas-tab" class="nav-link" data-toggle="tab" href="#second-panel" role="tab">Second</a> </li> </ul> <div class="tab-content"> <div class="tab-pane fade in show active" id="first-panel" role="tabpanel"> <form> <p>First tab contents</p> <div class="md-form"> <input type="text" name="password" id="password" class="form-control"> <label for="password">Password</label> </div> </form> </div> <div class="tab-pane fade" id="second-panel" role="tabpanel"> <p>Second Tab Contents</p> </div> </div>
Regards,
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: General Bootstrap questions
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No