Problem with bootstrap

1

I have a problem here in my TCC, I'm creating a web application, in the front end of my project I have a screen that contains a tab with two fields, when clicking a form appears for the user to pre-fill and click the other other form. My problem is that the two forms are appearing on both tabs. Does anyone have any tips ???

<script>
 $(".pagination").find('a').each(function(){
  $(this).click(function(e){                
    e.preventDefault();
    $("a[href='#notas']").tab('show');
  });
});
</script>
<ul id="tabs_sistem" class="nav nav-tabs">
  <li id="tab_prest_contas" class="active">
    <a href="#prest_contas" data-toggle="tab">Prestação de Contas</a>
  </li>
  <li id="tab_notas">
    <a href="#notas" data-toggle="tab">Notas Fiscais</a>
  </li>
</ul> 

As you have asked ... there is the code ... I am using a javascript script to make the tabs work and I added an id on each form ...

In this image is the script that I'm using and the html of the tabs ... in the forms, put inside a div in each with the ids that appear in the image ...

    
asked by anonymous 07.11.2014 / 02:23

1 answer

9

Your markup indicates that you are using plugin Toggle tabs of Bootstrap.

Your problem

If you look at your code and check the Bootstrap documentation for the plugin Togglable tabs , the way you're activating it is incorrect for two reasons:

  • When you use:

    <a href="#prest_contas" data-toggle="tab">Prestação de Contas</a>
    

    You are activating the plugin with the data attribute, you do not need to use JavaScript, but in your question you are using both.

    In the documentation:

      

    You can activate a tab or pill without writing any JavaScript by simply specifying data-toggle="tab" or data-toggle="pill" on an element.

    What translated:

      

    You can enable tab or pill navigation without writing any JavaScript simply by specifying dados-toggle="tab" or data-toggle="pílula" in an element.

  • When enabled via JavaScript:

    Each trigger has to be instantiated independently, something that you are trying to do but incorrectly since you are relating all tabs to the same panel:

    Your current code

    /* Este teu código precisa de ser ajustado
     */
    $(".pagination").find('a').each(function(){
        $(this).click(function(e){                
            e.preventDefault();
            $("a[href='#notas']").tab('show');   // ←-- A falhar aqui porque
        });                                      //     esta chamada ativa o
    });                                          //     separador via "nome"
                                                 //     e é sempre ID #notas
    

    Your rectified code

    See example in JSFiddle

    /* Dentro do contentor 'pagination' localizar
     * os triggers de cada painel e associar os
     * mesmos ao seu separador
     */
    $('.pagination .nav-tabs a').each(function() {
    
        $(this).click(function(e) {
            e.preventDefault();
    
            $(this).tab('show'); // apresentar o meu painel
        });
    });
    
    The trigger knows who your panel is because it is referenced in the href attribute.

     /* Dentro do contentor 'pagination' localizar
      * os triggers de cada painel e associar os
      * mesmos ao seu separador
      */
     $('.pagination .nav-tabs a').each(function() {
         
         $(this).click(function(e) {
             e.preventDefault();
            
             $(this).tab('show'); // apresentar o meu painel
         });
     });
    
      
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
     <div class="pagination">
         <ul id="tabs_sistem" class="nav nav-tabs">
             <li id="tab_prest_contas" class="active">
                 <a href="#prest_contas">Prestação de Contas</a>
             </li>
             <li id="tab_notas">
                 <a href="#notas">Notas Fiscais</a>
             </li>
         </ul>
         <div class="tab-content">
             <div class="tab-pane active" id="prest_contas">
                 <p>Painel para Prestação de Contas</p>
             </div>
             <div class="tab-pane" id="notas">
                 <p>Painel para Notas Fiscais</p>
            </div>
         </div>
     </div>
     
     
  • General considerations

    Markup of plugin

    The same has a markup to make things work as expected:

    <!-- Separadores de navegação -->
    <ul class="nav nav-tabs" role="tablist">
      <li role="presentation" class="active">
        <a href="#idMeuPainel1" role="tab" data-toggle="tab">Formulário 1</a>
      </li>
      <li role="presentation">
        <a href="#idMeuPainel2" role="tab" data-toggle="tab">Formulário 2</a>
      </li>
    </ul>
    
    <!-- Paineis dos separadores -->
    <div class="tab-content">
      <div role="tabpanel" class="tab-pane active" id="idMeuPainel1">
        <!-- o teu formulário 1 aqui -->
      </div>
      <div role="tabpanel" class="tab-pane" id="idMeuPainel2">
        <!-- o teu formulário 2 aqui -->
      </div>
    </div>
    

    As you can see from the example above, each trigger refers to a panel and the relationship between the trigger and the panel is performed by the panel ID:

    <a href="#idMeuPainel2" role="tab" data-toggle="tab">Formulário 2</a>
             │└────┬─────┘
             │     │       
             │     └────────────────────────────────┐ <!-- exatamente iguais -->
             ↓                                      │
    <!-- # = indicador de ID -->                    │
                                              ┌─────┴────┐
    <div role="tabpanel" class="tab-pane" id="idMeuPainel2"></div>
    

    Note: Each trigger must point to a single panel and the IDs must be unique on the entire page.

    First Tab Active

    The CSS class active is responsible for displaying an open tab when starting the plugin .

    It should be present in both the parent of the trigger and the panel element.

    In the example in this answer, the parent of the trigger is one and the panel is <div/> :

    <li role="presentation" class="active"> <!-- ... --> </li>
    
    <div role="tabpanel" class="tab-pane active" id="idMeuPainel1"> <!-- ... --> </div>
    

    Note:

    Only one parent of a trigger and only one dashboard can be with class active or unexpected behavior is the case when loading multiple page visible panels.

    Other issues of appearing two panel

    Often two panels are also encountered because of markup faults or duplication of id :

    • markup failure

      If you have two panels but the first one does not have the closing tags present or in the correct order, the HTML will be misinterpreted and when that panel is visible, what is below is also.

    • Duplication of id

      If two panels have the same id , calling this id will display both panels.

    07.11.2014 / 11:55