0
votes

I've built a Nav bar with a profile dropdown (right hand side of menu):

http://www.bootply.com/Rqj51l2VFO

<nav class="navbar navbar-inverse">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
      </div>
      <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav" <!--style="width:96%" -->>
          <li><a href="{$settings['web_process_url']}?function=show_open_cases">Open Cases</a></li>
          <li><a href="{$settings['web_process_url']}?function=show_closed_cases">Closed Cases</a></li>
          <li><a href data-toggle="modal" data-target="#create_case" data-backdrop="true">Raise New Case</a></li>
          <li class="active"><a href="#">{$case['object_ref']}</a></li>
          <!-- <li style="float:right;"><a href="" data-toggle="modal" data-target="#help-modal"><span class="glyphicon glyphicon-question-sign"/></a></li> -->
        </ul>

        <!-- http://bootsnipp.com/snippets/featured/account-in-navbar -->
        <ul class="nav navbar-nav navbar-right">
          <li class="dropdown" id="menu">
            <a href="#" data-toggle="dropdown">
              <span class="glyphicon glyphicon-user"></span>
              <strong>{$person['name']}</strong>
              <span class="glyphicon glyphicon-chevron-down" style="margin-left: 10px;"></span>
            </a>
            <ul class="dropdown-menu">
              <li>
                <div class="navbar-login" style="width: 400px;">
                  <div class="row">
                    <div class="col-lg-4">
                      <p class="text-center"><span class="glyphicon glyphicon-user icon-size" style="font-size: 75px;"></span></p>
                      <p><a href="#" data-toggle="collapse" data-target="#change_pic">Change Photo</a></p>
                    </div>
                    <div class="collapse" id="change_pic">
                      <p>Hi!</p>
                    </div>
                    <div class="col-lg-8">
                      <p class="text-left"><strong>Email Address</strong></p>
                      <p class="text-left small">{$person['main_location[email]']}</p>
                    </div>
                  </div>
                </div>
              </li>
              <li class="divider"></li>
              <li>
                <div class="navbar-login navbar-login-session">
                  <div class="row">
                    <div class="col-lg-3"></div>
                    <div class="col-lg-6">
                      <p><a href="{$settings['web_process_url']}?logout=1" class="btn btn-danger btn-block">Logout</a></p>
                    </div>
                    <div class="col-lg-3"></div>
                  </div>
                </div>
              </li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </nav>

When I click the change photo link, I want a Div to open and the menu to stay open so the user can interact with an input that shows I.e the user would enter a URL to the photo they want in the profile.

This works fine but the menu disappears. So I added the following JS so the menu stays:

JS:

$('#menu .dropdown-menu').on({
  "click": function(e) {
    e.stopPropagation();
  }
});

The issue I have is that now the menu stays open - the bootstrap collapse class isn't working to show/hide.

Could anybody explain what I'm doing wrong here please?

1

1 Answers

0
votes

Here is one way to keep the dropdown open after click and keep collapse class working to show/hide. ...

add ID to your Change photo button:

<p><a href="#" id="change-photo" data-toggle="collapse" data-target="#change_pic">Change Photo</a></p>

use this following function:

$('#change-photo').on('click', function () {
    $('#change_pic').toggle();
    return false;
});

check it out here: http://www.bootply.com/8Yo0fBXgN9#