0

I've set Bootstrap's dropdown menu to not close when clicking anywhere else and the select element to not close when being clicked on:

Here's the Codepen link to the example.

JS:

$('.dropdown.keep-open').on({
    "shown.bs.dropdown": function() { this.closable = false; },
    "click":             function() { this.closable = true; },
    "hide.bs.dropdown":  function() { return this.closable; }
});

$('select.form-control').on({
    "click":             function() { this.closable = false; },
});

HTML:

<div class="btn-group dropdown keep-open">
      <button class="btn btn-default toggle-dropdown pull-right dropdown keep-open" id="saveProject" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Save to Projects</button>
      <ul class="dropdown-menu dropdown-menu-left">
    <div id="projectDetails" class="dropdown-margins">
              <h4 class="project-header">Project Name</h4>
              <select class="form-control" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true">
                <ul class="dropdown-menu dropdown-menu-right">
                      <option value="one">One</option>
                      <option value="two">Two</option>
                      <option value="three">Three</option>
                      <option value="four">Four</option>
                      <option value="five">Five</option>
                </ul>
              </select>

              <p class="project-description">
                Description:
              </p>
              <input class="form-description project-description-margin" />

              <button class="btn btn-success">Save</button>
              <button class="btn btn-warning" id="closeProject">Discard</button>

          </div>
      </ul>
</div>

1 Answer 1

1

update the following method in your jquery

$('select.form-control').on({
"click":function() { event.stopPropagation(); },});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.