Bootstrap Input Group with Dropdown Menu - html

I am using a Legacy Bootstrap version (2.3) to support a tool that is not planned for upgrade anytime soon.
I am trying to make a simple Filter Style Dropdown & Input Group but I am having some issues with the menus.
Here is my code:
<div id="main" class="container">
<div class="page-header">
<h3 class="text-info">
Training Summary <small>Schedule Breakdown</small>
<span class="pull-right">
<div class="input-prepend input-append">
<button tabindex="-1" data-toggle="dropdown" class="btn dropdown-toggle">
Start Date <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
<input class="span2 dp cen" type="text" placeholder="Select a Start Date" name="startDate">
<button tabindex="-1" data-toggle="dropdown" class="btn dropdown-toggle">
End Date <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
<input class="span2 dp cen" type="text" placeholder="Select an End Date" name="endDate">
<button class="btn" type="button" name="fetch"><i class="icon-refresh"></i></button>
</div>
</span>
</h3>
</div>
What I am trying to do is get the dropdown menus to fire when you click on the "Start Date" or "End Date" dropdowns. Nothing appears to be happening and I'm not too sure why.
I created a fiddle to show the issue: http://jsfiddle.net/3h6x6ztw/1/
My goal is to get the dropdown menu to show up under the buttons as they normally would in a dropdown menu. Not sure if it's something I am missing or just a syntax issue.

In Bootstrap plugins can be included individually (using Bootstrap's individual *.js files), or all at once (using bootstrap.js or the minified bootstrap.min.js).
Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs. Also note that all plugins depend on jQuery (this means jQuery must be included before the plugin files).
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
Also you have to set a content for the button an the ul.dropdown-menu with position: relative because ul.dropdown-menu has position: absolute the default in bootstrap is btn-group
something like this:
<div class="btn-group">
<button tabindex="-1" data-toggle="dropdown" class="btn dropdown-toggle">
Start Date <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Action</li>
</ul>
</div>
Here a jsfiddle example to play with

Related

Assigning values to classes in html - UI Bootstrap

I have a dropdown in my html:
<div class="btn-group" uib-dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
<li role="menuitem">Action</li>
<li role="menuitem">Another action</li>
<li role="menuitem">Something else here</li>
<li class="divider"></li>
<li role="menuitem">Separated link</li>
</ul>
</div>
Wherein, I'm using thymeleaf template in my html. I got to know that, spring thymeleaf does not allow any incomplete options in the working html.
<html xmlns:th="http://www.thymeleaf.org">
And while launching this via Spring Boot App, I get an exception,
Attribute name "uib-dropdown" associated with an element type "div"
must be followed by the ' = ' character.
Can someone help me with what would I assign this uib-dropdown, uib-dropdown-toggle and uib-dropdown-menu options?
You can append angular attributes or directives with data-<ng att>
<div class="btn-group" data-uib-dropdown="" is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
<li role="menuitem">Action</li>
<li role="menuitem">Another action</li>
<li role="menuitem">Something else here</li>
<li class="divider"></li>
<li role="menuitem">Separated link</li>
</ul>
</div>

Bootstrap Dropdown Angular2 not working

Is it a problem with my browser that this dropdown is not working?
I wanted to add a dropdown menu in a navbar in one of my projects and it wasn't opening, so i took the example from bootstrap and it doesn't even work in a code snippet on jsfiddle.net . I am using Angular2
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria- expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div>
It is working, just add the .js file of Bootstrap and jquery.min.js
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria- expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div>
Basically, Dropdown requires Jquery and bootstrap.js to be included in the page.
In Angular, you will not be requiring JQuery. But, bootstrap.js is fully dependent on JQuery.
So the alternative for bootstrap.js in Angular is ngx-bootstrap(https://github.com/valor-software/ngx-bootstrap). By adding ngx-bootstarp as a dependency to your project will help you. Thanks for Volarkin for developing it.
Example http://valor-software.com/ngx-bootstrap/#/dropdowns
I faced similar issue that Nav bar dropdown not working. I fixed it by following the below steps.
In Angular.json add below lines
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"node_modules/popper.js/dist/umd/popper.min.js"
]
"styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css" ]
Because bootstrap has dependencies on both jquery and popper.js

Bootstrap adjust dropdown-menu width

I am using a dropdown-menu to show the candidate options I can choose. And I also want an input to filter the options, so when I enter something, the dropdown-menu should also be shown. So I want to adjust the width of the dropdown-menu to be equal to the input. And how can I show it when the I enter something in the input?
The html I current use is:
<div class="input-group">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div><!-- /btn-group -->
Actually you are searching for some kind of suggestion search box with given selectable choices if I understood correctly.
See this thread:twitter bootstrap autocomplete dropdown / combobox with Knockoutjs
Solution suggestions: selectize.js or Select2
The aspect of automatically adjusting the dropdown's width to be equal to the input's width is hard to achieve because it would cut off some of your given choices (example: Input is only one character - Dropdown would only show first character of every choice). This can't be what you want to achieve.
possible solution:
$('.dropdown-menu').width($('.input-group').width());
.input-group{
width:33%;
}
<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.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="input-group">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div><!-- /btn-group -->

Override not working with bootstrap when fetching css from maxcdn server

I am using bootstrap framwork and trying to change few properties with navbar, like background color,
When I uses css from a local copy like, ./bootstrap.css override works fine or when I pasting whole css or just navbar css to liveweave CSS column override working.
But
when I am using maxcdn server like
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
Override is failing whether its liveweave or my pc, even after using !important override fails.
I am using
navbar navbar-default navbar-fixed-top
classes
I am sure about what I said above, even before posting this question I visited at least 10 pages or similar question to find solution but none them used CSS from maxcdn server.
Working Example
<!DOCTYPE html>
<html>
<head>
<title>HTML5, CSS3 and JavaScript demo</title>
<script src="./google.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"> </script>
<link rel="stylesheet" href="./main.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</body>
</html>
main.css
.navbar-default{
background-color:red;
}
If you use a local css file for override. you must be sure this file is read after the maxcdn...... file. the last one is the css element used
Having the same issue... I noticed that, when viewing the maxcdn bootstrap.min.css in my text editor, the code stops running at ".glyphicon-phone:before{content:"\e145"}.glyphicon..." so I wonder if that is relating to the issue. Hoping that it gets sorted out soon!

Google Custom Search conflicting with Bootstrap and Skipping a Line in NavBar

I just incorporated Google Custom Search into my Bootstrap powered NavBar. Some weird formatting occurred which I fixed by adding the below CSS code.
This fixed many of the issues but there is still one left: the search box forces a line skip within my NavBar.
Below is my HTML and CSS code.
HTML code (basically the bootstrap template replacing their search form with Google's):
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<!-- Google search -->
<!-- <gcse:search></gcse:search> -->
<div style="width: 20%;">
<gcse:search></gcse:search>
</div>
<!-- Bootstrap search -->
<!-- <form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Android Term">
</div>
<button type="submit" class="btn btn-default">Search</button>
</form> -->
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
CSS code
/* AM22 - To make google search box appear correct */
input.gsc-input, .gsc-input-box, .gsc-input-box-hover, .gsc-input-box-focus, .gsc-search-button
{
box-sizing: content-box;
line-height: normal;
}
/* AM22 - To make google search results tabs appear correct */
.gsc-tabsArea div
{
/*By default, Google custom search CSS sets it as AUTO, which shows scroll bars*/
overflow: visible;
}
.nowrap {
white-space: nowrap;
}
I tried a few variations of the nowrap attribute, the nobr tag and white-space: nowrap; but none of these worked. Any suggestions?
For my website (link in my comment above) I placed the search box in the <div class="navbar-header">
I believe I also had to manually set the width so it wasn't full-page width.
Now about styling my version...