Bootstrap: Modal with dropdown for caption

Asked

Viewed 1,029 times

0

I would like to use the bootstrap modal to open a list of subtitles. But I would like to display the meaning only when clicked on the legend. Got a way? Don’t need to have styles just do a slidown.

I used a javascript to carry a div:

'<script type="text/javascript" language="javascript">
function abreFecha(sel) {
$(sel).slideToggle();
}
</script>'

<a class="btn btn-primary" data-toggle="modal" data-target="#modal-
mensagem"> 
<span class="glyphicon glyphicon-th-list"></span> Ver Legendas
</a>

<div class="modal fade" id="modal-mensagem">
<div class="modal-dialog">
    <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
<span>×</span></button> 
         </div>
         <div class="modal-body">

  <?php 
       include 'includes/legenda.php';
        ?>
             <br>
             <div id="sigla"> O significado vai aqui</div>   

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
        </div>
     </div>
</div>

caption.php:

 <div class="container-fluid">
 <div class="row">
<a href="javascript:abreFecha('#sigla')" class="col-md-1">SS</a>
<a href="javascript:abreFecha('#sigla')" class="col-md-1">ABC</a>
<a href="javascript:abreFecha('#sigla')" class="col-md-1">ECO</a>


</div>
</div>

So now you’re opening a modal with a few acronyms, and clicking opens the div with the meaning. The question now is: How to display a different text in the same div ? Knowing that each acronym has a caption? I would like to have the meaning on the caption page, so it is cleaner the main page.

  • What was your attempt?

  • how is the legend?

  • AP < this is the abbreviation. Apartment = is the abbreviation of apartment/ < this is the caption that appears when you click.

  • Try to make a kind of a dropdown menu inside, but it got very buggy. I know the bootstrap has some menus, can you get some of the style ? I will work more enoite, if anyone has any idea or path to point, already help enough.

  • Good night. I think what you want a Popover, here shows how to do: https://getbootstrap.com/docs/4.0/components/popovers/ Another option would be to use a Tooltip: https://getbootstrap.com/docs/4.0/components/tooltips/ I hope I helped.

  • You mean a list of subtitles and open a modal by clicking an item from that list

  • Inside the modal, a list of Acronyms SS AB CC . Same thing as calling a content in a DIV with javascript and css, but there’s something in the bootstrap pattern, so it doesn’t look so different ?

Show 2 more comments

2 answers

0

To change the content of <div id="sigla"> O significado vai aqui</div>

create a function for each onclik event from each link

function ss() {
document.getElementById("sigla").innerHTML = "<p>AP Apartamento = é a abreviação de apartamento/<p><p>TAL	<span style='color:red'>TALcoisa =  é a abreviação de apartamento de tal coisa</span></p>";
}

function abc() {
document.getElementById("sigla").innerHTML = "<p>Geom Geometria = é a abreviação de geometria/<p><p>TAL	<span style='color:blue'>TALcoisa =  é a abreviação de geometria de tal coisa</span></p>";
}

function eco() {
document.getElementById("sigla").innerHTML = "<p>Agr Agricultura = é a abreviação de agricultura/<p><p>TAL	<span style='color:green'>TALcoisa =  é a abreviação de agricultura de tal coisa</span></p>";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<a class="btn btn-primary" data-toggle="modal" data-target="#modal-mensagem"> 
<span class="glyphicon glyphicon-th-list"></span> Ver Legendas
</a>

<div class="modal fade" id="modal-mensagem">
<div class="modal-dialog">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal">
			<span>×</span></button> 
		</div>
		<div class="modal-body">
			<div class="container-fluid">
				<div class="row">
					<a href="#" class="col-md-1" onclick="ss()">SS</a>
					<a href="#" class="col-md-1" onclick="abc()">ABC</a>
					<a href="#" class="col-md-1" onclick="eco()">ECO</a>
				</div>
			</div>
			
			<br>
			<div id="sigla"></div>   
		
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
		</div>
	</div>
</div>
</div>

  • I believe javascript does not need, bootstrap already takes care of that?

0


I believe that what you want can be achieved without extra javascript, using the bootstrap accordion. Another option would still be a navigation with vertical tabs. See this example:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <div class="container">
    <h2>Legendas</h2>
    <!-- Trigger the modal with a button -->
    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">
      <span class="glyphicon glyphicon-th-list"></span> Legendas
    </button>

    <!-- Modal -->
    <div class="modal fade" id="myModal" role="dialog">
      <div class="modal-dialog">
      
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Legendas</h4>
          </div>
          <div class="modal-body">
            <p>Clique na sigla para ver o significado.</p>

            <!-- início do accordion -->
            <div class="panel-group" id="accordion">
              <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapse1">SS</a>
                  </h4>
                </div>
                <div id="collapse1" class="panel-collapse collapse">
                  <div class="panel-body">Significado de SS.</div>
                </div>
              </div>
              <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapse2">ABC</a>
                  </h4>
                </div>
                <div id="collapse2" class="panel-collapse collapse">
                  <div class="panel-body">Significado de ABC.</div>
                </div>
              </div>
            </div> <!-- fim do accordion -->

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
        
      </div>
    </div> <!-- fim do modal -->
    
  </div>

Source

  • Perfect friend, this is exactly what I wanted :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.