Ngbootstrap: how to position dropdown under search input - css

I'm following this documentation cause I would like to create a
Gmail like 'search bar' where beside the input there's a dropdown button that opens a dropdown with filter options.
Unfortunately in the docs the examples don't cover the input + dropdown button scenario.
I started with this:
<!-- Search bar-->
<div class="input-group mb-3">
<input type="text" class="form-control">
<div class="input-group-append" ngbDropdown role="group" aria-label="Button group with nested dropdown">
<button class="btn btn-outline-success" ngbDropdownToggle></button>
<div class="dropdown-menu" ngbDropdownMenu>
<button class="dropdown-item">One</button>
<button class="dropdown-item">Two</button>
</div>
</div>
</div>
Everything is shown correctly, but the dropdown is not. It is opened under its parent (the button), while I'd like to have it for the whole length of the input. Pretty sure it could be solved with some CSS rule.

From the documentation under Manual Triggers, you could attach the dropdown menu to the input group and trigger the open/close with the appended button on click event.
<!-- Search bar-->
<div class="container">
<div class="input-group mb-3" #myDrop="ngbDropdown" ngbDropdown>
<input type="text" class="form-control" >
<div class="input-group-append" role="group" >
<button (click)="$event.stopPropagation(); myDrop.open();" class="btn btn-outline-success" >Hi</button>
</div>
<div class="dropdown-menu" ngbDropdownMenu>
<button class="dropdown-item">One</button>
<button class="dropdown-item">Two</button>
</div>
</div>
</div>

Related

Why won't my button and links naturally fall underneath the input?

I would like to place Have an account?, Login button, and Link A Link B directly underneath something something something something, Enter Zip Code input field and Enter Zip Code button.
The way I've set up my Bootstrap (version 3.3.7) and HTML, I'd think that it would've appeared underneath but it's actually displaying the complete opposite of what I expect. Instead, it's all the way on the left side as per the picture below.
Why's is carrying out this behavior? If more information is needed please let me know.
picture of what I'm describing
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="col-7">
<form class="pull-right col-12 zipSection">
<h6 class="pull-right">something something something something</h6>
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Zip Code">
</div>
<button type="submit" class="btn btn-default center-block enterZipCodeButton">Enter Zip Code</button>
</form>
<div class="col-12">
<p class="col-12">Have an account?</p>
<button type="submit" class="loginButton" onclick="document.location = '/'">Login</button>
Link A
Link B
</div>
</div>
</div>
Your form has a class called pull-right (which has been renamed to float-right in Bootstrap 4). What that does is forces the div to the far right. Since this is bootstrap, everything else adapts, which means the div which theoretically should be under, gets forced up to the top row, and to the left (since left-alignment is the default). A solution to that is to use the class of row from the Bootstrap grid system. Every row you want, you make a new div with a class of row. This way, they will now be under each other.
However, the Have an account? would still be on the left. To fix that, give it a class of pull-right.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-7">
<form class="pull-right col-12 zipSection">
<h6 class="pull-right">something something something something</h6>
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Zip Code">
</div>
<button type="submit" class="btn btn-default center-block enterZipCodeButton">Enter Zip Code</button>
</form>
</div>
</div>
<div class="row">
<div class="col-12 pull-right">
<p class="col-12">Have an account?</p>
<button type="submit" class="loginButton" onclick="document.location = '/'">Login</button>
Link A
Link B
</div>
</div>
</div>

how to create a radio button that acts as a tab controller in spring mvc

i want to have a radio buttons that acts as tab controller same as in below jsfiddle: http://jsfiddle.net/bizamajig/mju8gzwa/
i have created the same thing in jsp with with spring tag as below.i am facing null exception in getting the selected tab value in my controller.i want to know which tab selected and based on tab selection i will query different data.
how to get which tab is selected
enter code here
<div class="container">
<div class="row">
<div id="tab" class="btn-group" data- toggle="buttons">
<a href="#daily" class="btn btn-default
active" data-toggle="tab">
<form:radiobutton path="recurrence" value="d" />Daily</a>
<a href="#features" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="w" />Weekly</a>
<a href="#requests" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="m" />Monthly</a>
<a href="#contact" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="o" />Once</a>
</div>
<div class="tab-content">
<div class="tab-pane active" id="prices">Prices content</div>
<div class="tab-pane" id="features">Features Content</div>
<div class="tab-pane" id="requests">Requests Content</div>
<div class="tab-pane" id="contact">Contact Content</div>
</div>
</div>
</div>
someone please help to get this working?
You can know which tab is activated currently. Based on that you can query data.
Just add below code in your jfiddle's javascript/Jquery part.
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href") // activated tab
$(target).show();
alert(target);
});

Bootstrap NavBar non-collapsable input field

I have a nav Bar with a input field and a couple links
but I want just the links to be collapsed.
I'm trying to get this work for a few hours with no success.
It doesn't stay on a single row
What I want is something like this
Desktop
| [Brand Name] [Input field___________________________(Search)] [Button] [Button] |
Mobile
| [Brand Name] [Input field (Search)] [#] |
|---------------------------------------------|
| Button |
| Button |
http://www.bootply.com/G1JJxeMQA0#
another atempt http://www.bootply.com/n3raobttyd
Take a look at this:
https://jsfiddle.net/9L3b08zf/
If you change the size of the result grid, you will see how the link will jump form side to bottom.
I have used the bootstrap grid to achieve this.
<div class="row">
<div class="col-md-6 search">
<form class="navbar-form" role="search" method="get" id="search-form" name="search-form">
<div class="input-group">
<input type="text" class="form-control" placeholder="e.g.: www.google.com" id="query" name="query" value="">
<div class="input-group-btn">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"> Locate</span></button>
</div>
</div>
</form>
</div>
<div class="col-md-6 buttons">
<div class="collapse navbar-collapse navbar-ex1-collapse ">
<div class="row">
<div class="col-md-6"><a data-toggle="modal" href="#" data-target="#">Login</a></div>
<div class="col-md-6"><a data-toggle="modal" href="#" data-target="#">Register</a></div>
</div>
</div>
</div>

Flexible width input field in Bootstrap 3 Navbar

I'm trying to create a navigation bar which contains an input field. I would like the input field to occupy all available space in the navigation bar.
Following this answer, I successfully created a layout similar to what I want, which contains an "addon" icon to the left of the input field (see code here).
But: I don't want the icon near the input field.
The following code controls the input field:
<form class="navbar-form">
<div class="form-group" style="display:inline;">
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" class="form-control">
</div>
</div>
</form>
The problem is that removing <span class="input-group-addon">...</span> to get rid of the icon, makes the input field contract to a smaller size and loose the rounded edges (which is less important. see code here).
Of course it doesn't make sense to wrap a single input field in an "input-group". But removing the "input-group" wrapper causes the input field to expand and break into a new line (see code here).
After looking at Bootstrap.css I tried to create a new css class which mimics the relevant code of the input-group class. This brings back the input field inline in the navbar, but still does not make it expand to occupy all available space (see code here).
My question is: How do I get the layout I want without the icon?
Bonus: Why are the "input-group" and the icon making the input field expand?
Required browser compatibility: Chrome, Firefox, IE8+
Well, most folks didn't used have to design with tables, but in 99 when I began, tables created the layouts and we used spacer .gifs and all kinds of crap to design with. When you have a display:table on the container and a display:table-cell on the contents inside it, since the .form-control is empty there has to be something else to force the width of the element to take up the space, or it's going to act like an empty cell. So you have to have an empty span with some padding on it to force it.
http://jsbin.com/aXOZEXi/1 -- Bootstrap 3.0 - 3.1
http://jsbin.com/aXOZEXi/2/edit -- Bootstrap 3.2
.test {
display:table;
}
.test > .form-control {
display: table-cell;
margin-left:-3px;
}
.test > span {
display: table-cell;
width:1%;
padding:0 3px;
}
HTML
<form class="navbar-form">
<div class="form-group" style="display:inline;">
<div class="test">
<span><!--shim--></span>
<input type="text" class="form-control">
</div>
</div>
</form>
Replace with this html: (made changes to glyphicon glyphicon-search and background-color, border of input-group-addon) Made the round edges too :)
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapsible">
<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="#">Some Brand</a>
</div>
<div class="navbar-collapse collapse" id="navbar-collapsible">
<ul class="nav navbar-nav navbar-left">
<li>Link 1</li>
<li>Link 2</li>
</ul>
<div class="navbar-form navbar-right btn-group">
<button type="button" class="btn btn-default">Button 1</button>
<button type="button" class="btn btn-default">Button 2</button>
<button type="button" class="btn btn-default">Button 3</button>
</div>
<form class="navbar-form">
<div class="form-group" style="display:inline;">
<div class="input-group">
<span class="input-group-addon" style="background-color:transparent; border:none"><span class=""></span></span>
<input type="text" class="form-control" style="border-bottom-left-radius: 4px;border-top-left-radius: 4px;">
</div>
</div>
</form>
</div>
</div>
</nav>
</div>
Worked really hard to get to what you require. hope you appreciate :)
This will get you pretty much where you want to be
<div class="form-group" style="display:inline;">
<div class="input-group col-lg-6 col-md-5 col-sm-3 center-block col-xs-12">
<input class="form-control" type="text" placeholder="Search">
</div>
</div>
It will not fill exactly all the space but it will fill most of it and will center the search box so it does not look out of place. Added more dynamic column sizing extra small screen uses a dropdown menu so I re-sized the box to fit the screen. to build a fully responsize page as you are describing you should probably nest everything inside a grid because col-?-? is not a fixed width it is a percentage width based on it's container.

Twitter Bootstrap form-inline Not Lining Controls Up

I'm using Twitter Bootstrap in a Rails application. I'm trying to line up a search field with the Search button and a Help button which will use the Accordion Javascript control to expand the area below with Help content.
I have everything working, but, the Help button isn't staying on the same line as the other controls. The accordion control requires a DIV so I'm not sure if that's causing a problem. Instead of staying on the same line the Help button appears just below the search field left aligned.
Here is my code:
<p><strong>Enter Search Criteria</strong></p>
<form class="form-inline">
<input type="text" class="input-large" placeholder="Name, Phone, Conf Rm" autofocus >
<button type="submit" class="btn">Search</button>
<div class="details">
<!-- accordian button -->
<div class="accordion">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseHelp"> <button type="link" class="btn btn-info btn-small">
<i class="icon-question-sign"></i>
</button></a>
</div>
</form>
</div>
<!-- Accordian area -->
<div id="collapseHelp" class="accordion-body collapse style="height: 0px; ">
<div class="accordion-inner">
<p><strong>Person Search:</strong> Last Name, First Name (e.g. Smith, John)</p>
<p><strong>Conference Room Search:</strong> Plaza-Building, Suite-Name (e.g South-I2W-20E-1)</p>
<p><strong>Phone Number Search:</strong> Please provide at least the last 4 digits of the phone number (e.g. 8686)</p>
</div>
</div>
<!-- End accordian area -->
All help is greatly appreciated.
Thanks
Your accordion button does not need to reside within a container in order to function, so just remove the .details and .accordion containers and your button should line up with the rest of the control buttons just fine.
HTML
<p><strong>Enter Search Criteria</strong></p>
<form class="form-inline">
<input type="text" class="input-large" placeholder="Name, Phone, Conf Rm" autofocus >
<button type="submit" class="btn">Search</button>
<!-- accordian button -->
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseHelp"> <button type="link" class="btn btn-info btn-small">
<i class="icon-question-sign"></i>
</button></a>
</form>
<!-- Accordian area -->
<div id="collapseHelp" class="accordion-body collapse" style="height: 0px; ">
<div class="accordion-inner">
<p><strong>Person Search:</strong> Last Name, First Name (e.g. Smith, John)</p>
<p><strong>Conference Room Search:</strong> Plaza-Building, Suite-Name (e.g South-I2W-20E-1)</p>
<p><strong>Phone Number Search:</strong> Please provide at least the last 4 digits of the phone number (e.g. 8686)</p>
</div>
</div>
<!-- End accordian area -->
Demo:
http://jsbin.com/eyajig/1

Resources