Add items to Bootstrap Dropdown from Code Behind
Tag : chash , By : Amin Amini
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a dropdown from boostrap such as this: , You will need a repeater. Repeater1.DataSource = yourdatasource
Repeater1.Databind()
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate><Ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"></HeaderTemplate>
<ItemTemplate>
<li role="presentation">
<a role="menuitem" href="#"> <%# Eval("yourfieldfromcodebhind here") %> </a>
</li>
</ItemTemplate>
</asp:Repeater>
|
Bootstrap Dropdown expands but does not contain any Items
Date : March 29 2020, 07:55 AM
should help you out Using Bootstrap you dont need <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
</head>
<body>
<!--Default buttons with dropdown menu-->
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<!--Primary buttons with dropdown menu-->
</body>
|
Bootstrap button dropdown child element's class is getting removed when clicked on other button's dropdown items
Date : March 29 2020, 07:55 AM
it fixes the issue The problem occurs because you are using parents instead of parent: This line of code is the problem: thisEl.parents('li').siblings().find('a').removeClass('active-select'); // parents targets all li's above `a` and hence siblings afterwards targets other drop-downs.
thisEl.parent('li').siblings().find('a').removeClass('active-select');
(function () {
var search_btn = $('.select-style').find('button.btn-inverse'),
selectOptions = $('.select-style ul.dropdown-menu li').find('a');
selectOptions.on('click', function (e) {
e.preventDefault();
var thisEl = $(this);
var getTextData = thisEl.text();
thisEl.addClass('active-select');
// Use .parent and not .parents
thisEl.parent('li').siblings().find('a').removeClass('active-select');
thisEl.parents('.btn-group').find('button[type=button]').html( getTextData );
});
}) ();
ul.homeInputBaropenState { list-style-type: none; width: 500px; }
ul.homeInputBaropenState li { display: inline; }
ul.homeInputBaropenState li a.active-select { color: blue; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<ul class="select-Section homeInputBaropenState">
<li class="select-style">
<div class="btn-group">
<button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Select City
</button>
<ul class="dropdown-menu">
<li><a href="#">New York</a></li>
<li><a href="#">San Fransisco</a></li>
<li><a href="#">Los Angeles</a></li>
<li><a href="#">Detroit</a></li>
</ul>
</div>
</li>
<li class="select-style">
<div class="btn-group">
<button type="button" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Select Type
</button>
<ul class="dropdown-menu">
<li><a href="#">Men</a></li>
<li><a href="#">Women</a></li>
<li><a href="#">Kids</a></li>
</ul>
</div>
</li>
<div class="clearfix"></div>
</ul>
|
Creating Django Filter in a bootstrap dropdown based on the django-admin created categories
Tag : django , By : Gerhard Miller
Date : March 29 2020, 07:55 AM
hope this fix your issue In accordance to the comment given by @TimS and some other helps from another community, I wrote a solution to filter by category and it works. Below is the hack that made its work: <div class="row" style="margin-bottom: 50px;">
<div class="col-sm-6 pull-right">
<form method="get">
<select id="men-filter-cat" class="form-control" name="category-filter" onchange="this.form.submit();">
<option value="all">Filter by category</option>
{% for c in categories %}
<option value="{{ c.category }}" {% if selected == c.category %}selected=selected"{% endif %}>
{{ c.category }}
</option>
{% endfor %}
</select>
</form>
</div>
</div>
class HomeView(View):
def get(self, request, *args, **kwargs):
mentors = Mentor.objects.all()
chosen_filter = self.request.GET.get('category-filter')
if chosen_filter:
mentors = mentors.filter(category__category=chosen_filter)
return render(request, "mentoring_application/home.html", {"mentors": mentors, 'selected': chosen_filter, 'categories': Category.objects.all().order_by('category')})
def profile(request, pk, template='mentoring_application/profile.html'):
mentor = get_object_or_404(Mentor, pk=pk) # pk is primary key, so url will be site.com/profile/3
context = {'mentor': mentor}
return render(request, template, context)
|
Responsive Bootstrap 4 navbar dropdown-items display as nav-items
Date : March 29 2020, 07:55 AM
will be helpful for those in need Use a @media query for mobile (<992px) to show the dropdown-menu as normal nav-links... @media (max-width: 992px) {
.dropdown-toggle {
display: none;
}
.dropdown-menu {
display: block;
position: relative;
border-width: 0;
padding: 0;
margin: 0;
}
.dropdown-item {
padding: .5rem 0rem;
color: rgba(0,0,0,.5);
}
}
|