admin管理员组文章数量:1425819
this is an extended question I encountered after my previous question.
The problem lies when someone clicked on the arrow to show the advanced searches, it drops down the form as expected. However, the moment when someone clicked on the select drop down, the whole dropdown menu would then collapse on it's own.
I've been trying to find out what element/trigger is causing this issue and see if there's a way to work around this, but I have no progress at all
Here's what I've observed so far
- [Expected] If the user clicked outside of the drop menu area, the menu collapses
- [Unexpected] If the user clicked any of the whitespace within the drop menu, the menu still collapses
- [Expected] if user clicked on the text field, checkbox, radiobox, textarea, they are supposed to be able to type and enter required texts.
- [Unexpected] If the user clicked a select menu, the dropmenu collapses instantly
I have dropped a sample code down below to demonstrate the question I have.
<link rel="stylesheet" href=".0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src=".2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src=".js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src=".0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-12">
<div class="input-group dropdown">
<input type="text" class="form-control" id="project_search" placeholder="search ...">
<div class="input-group-append">
<div class="btn-group">
<button class="btn bg-primary text-white" type="button">Search</button>
<button class="btn bg-primary text-white dropdown-toggle dropdown-toggle-split" id="searchAdvancedFilter" data-toggle="dropdown" data-boundary="window" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right p-3 w-100" aria-labelledby="searchAdvancedFilter">
<h6 class="dropdown-header">Advanced Settings</h6>
<div class="dropdown-divider"></div>
<div class="form-group">
<label for="option">Option Header</label>
<select class="form-control" id="option" name="option">
<option>Pick an option</option>
<option value=1>Option 1</option>
<option value=2>Option 2</option>
</select>
</div>
<div class="form-group">
<label for="inputtext">Input Header</label>
<input type="text" class="form-control" id="inputtext" name="inputtext">
</div>
<div class="form-group">
<label for="inputcb">Checkbox Header</label>
<input type="checkbox" class="form-control" id="inputcb" name="inputcb">
</div>
<div class="form-group">
<label for="inputradio">Radio Header</label>
<input type="radio" class="form-control" id="inputradio" name="inputradio">
</div>
<div class="form-group">
<label for="ta">TextArea Header</label>
<textarea class="form-control" id="ta" name="ta"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
this is an extended question I encountered after my previous question.
The problem lies when someone clicked on the arrow to show the advanced searches, it drops down the form as expected. However, the moment when someone clicked on the select drop down, the whole dropdown menu would then collapse on it's own.
I've been trying to find out what element/trigger is causing this issue and see if there's a way to work around this, but I have no progress at all
Here's what I've observed so far
- [Expected] If the user clicked outside of the drop menu area, the menu collapses
- [Unexpected] If the user clicked any of the whitespace within the drop menu, the menu still collapses
- [Expected] if user clicked on the text field, checkbox, radiobox, textarea, they are supposed to be able to type and enter required texts.
- [Unexpected] If the user clicked a select menu, the dropmenu collapses instantly
I have dropped a sample code down below to demonstrate the question I have.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery./jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn./bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-12">
<div class="input-group dropdown">
<input type="text" class="form-control" id="project_search" placeholder="search ...">
<div class="input-group-append">
<div class="btn-group">
<button class="btn bg-primary text-white" type="button">Search</button>
<button class="btn bg-primary text-white dropdown-toggle dropdown-toggle-split" id="searchAdvancedFilter" data-toggle="dropdown" data-boundary="window" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right p-3 w-100" aria-labelledby="searchAdvancedFilter">
<h6 class="dropdown-header">Advanced Settings</h6>
<div class="dropdown-divider"></div>
<div class="form-group">
<label for="option">Option Header</label>
<select class="form-control" id="option" name="option">
<option>Pick an option</option>
<option value=1>Option 1</option>
<option value=2>Option 2</option>
</select>
</div>
<div class="form-group">
<label for="inputtext">Input Header</label>
<input type="text" class="form-control" id="inputtext" name="inputtext">
</div>
<div class="form-group">
<label for="inputcb">Checkbox Header</label>
<input type="checkbox" class="form-control" id="inputcb" name="inputcb">
</div>
<div class="form-group">
<label for="inputradio">Radio Header</label>
<input type="radio" class="form-control" id="inputradio" name="inputradio">
</div>
<div class="form-group">
<label for="ta">TextArea Header</label>
<textarea class="form-control" id="ta" name="ta"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Share
Improve this question
asked Apr 13, 2018 at 7:27
Willy_SunnyWilly_Sunny
1993 silver badges15 bronze badges
1 Answer
Reset to default 4Bootstrap Dropdown menus will always close on click, except for when a <form>
is used. The way to prevent it from closing on click is to use a <form>
element inside dropdown...
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery./jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn./bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-12">
<div class="input-group dropdown">
<input type="text" class="form-control" id="project_search" placeholder="search ...">
<div class="input-group-append">
<div class="btn-group">
<button class="btn bg-primary text-white" type="button">Search</button>
<button class="btn bg-primary text-white dropdown-toggle dropdown-toggle-split" id="searchAdvancedFilter" data-toggle="dropdown" data-boundary="window" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right p-3 w-100" aria-labelledby="searchAdvancedFilter">
<h6 class="dropdown-header">Advanced Settings</h6>
<div class="dropdown-divider"></div>
<form>
<div class="form-group">
<label for="option">Option Header</label>
<select class="form-control" id="option" name="option">
<option>Pick an option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>
<div class="form-group">
<label for="inputtext">Input Header</label>
<input type="text" class="form-control" id="inputtext" name="inputtext">
</div>
<div class="form-group">
<label for="inputcb">Checkbox Header</label>
<input type="checkbox" class="form-control" id="inputcb" name="inputcb">
</div>
<div class="form-group">
<label for="inputradio">Radio Header</label>
<input type="radio" class="form-control" id="inputradio" name="inputradio">
</div>
<div class="form-group">
<label for="ta">TextArea Header</label>
<textarea class="form-control" id="ta" name="ta"></textarea>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://www.codeply./go/18ACVL2uzn
Another option is to use the jQuery stopPropagation()
method: https://www.codeply./go/4dVvDDpChW
$('.dropdown-menu').click(function(e) {
e.stopPropagation();
});
本文标签: javascriptBootstrap4 Dropdown Menu auto collapse when clicking select elementStack Overflow
版权声明:本文标题:javascript - Bootstrap4 Dropdown Menu auto collapse when clicking select element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745450924a2658878.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论