Multiple form-groups on single row in Bootstrap 4 - html

Does anyone know if this kind of thing is possible?
I've tried using inline-group and form-inline but then it doesn't seem to conform to fit the full grid width.
Whereas form-horizontal seems to expect the entire form on one row.
This code creates the desired output (two form controls on one row) but form-groups are required around each one for viewing in sm mode.
NB: This is for a 16 col grid.
<form>
<div className="form-group row">
<!--form group needed here -->
<label className="col-form-label col-md-2" htmlFor="formGroupExampleInput">First Name*</label>
<div className="col-md-5">
<input type="text" className="form-control" id="formGroupExampleInput" placeholder="Example input" />
</div>
<!--form group needed here -->
<label className="offset-md-2 col-form-label col-md-2" htmlFor="formGroupExampleInput">Last Name*</label>
<div className="col-md-5">
<input type="text" className="form-control" id="formGroupExampleInput" placeholder="Example input" />
</div>
</div>
</form>
I don't think this is a duplicate of:
Bootstrap 3: How to get two form inputs on one line and other inputs on individual lines?
...because this isn't leaving me with full control of grid columns within via form labels etc.

Place your form-groups into .col-* containers to align the groups in a horizontal layout, for example:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form>
<div class="col-xs-6 form-group">
<label for="inputEmail3" class="control-label">Email</label>
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
<div class="col-xs-6 form-group">
<label for="inputPassword3" class="control-label">Password</label>
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</form>
If controls of a form group should be aligned in a horizontal layout too, use .form-horizontal class for the form. In this case .form-groups behaves as grid rows. Thus, it is possible to apply Nesting columns template for your form:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form class="form-horizontal">
<div class="col-xs-6">
<div class="form-group">
<label for="inputEmail3" class="col-xs-3 control-label">Email</label>
<div class="col-xs-9">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="inputPassword3" class="col-xs-4 control-label">Password</label>
<div class="col-xs-8"><input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</div>
</form>

My bad, I just hadn't understood nested rows properly:
https://v4-alpha.getbootstrap.com/layout/grid/#nesting
This works fine:
<form>
<div class="row">
<div class="col-md-8">
<div class="form-group row">
<label class="col-form-label col-md-4" for="formGroupExampleInput">First Name*</label>
<div class="col-md-10">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" />
</div>
</div>
</div>
<div class="col-md-8">
<div class="form-group row">
<label class="offset-md-2 col-form-label col-md-4" for="formGroupExampleInput">Last Name*</label>
<div class="col-md-10">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" />
</div>
</div>
</div>
</div>
</form>

Related

Bootstrap horizontal form

I trying to create a horizontal form in bootstrap and have used the code they've given in the documentation. In the example they have given the input boxes fill the entire column space. For some reason this does not happen for me even if I copy the code. How to I get mine to be the same format?
Here is how it looks on the bootstap website
Here is an image of how this looks in my code
Here is my code:
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2>Account Details</h2>
<form action="/account" method="post" class="form-horizontal">
<div class="form-group row">
<label for="height" class="col-sm-2 col-form-label">Height</label>
<div class="col-sm-10">
<input class="form-control" type="number" value="{{ account_details[0].height }}" id="height" name="height" min=0 max=300 step=1>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</form>
</div>
</div>
</div>
It happened because of max='300'; when you set max condition for an input, size of that input change to max width that it needs to fill input for max value and because of that width change to a smaller input:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2>Account Details</h2>
<form action="/account" method="post" class="form-horizontal">
<div class="form-group row">
<label for="height" class="col-sm-2 col-form-label">Height</label>
<div class="col-sm-10">
<input class="form-control" type="number" id="heightname="height" min=0 step=1>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
The result with this should be like :
Thanks for the help, found bootstrap was interacting with something in my css page

Bootstrap 4 - can't horizontally align a vertical form

I have the following form code:
<div id="site" class="container-fluid">
<div class="row">
<div class="my-4 offset-3 col-6 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-2 col-form-label">Username</label>
<div class="col-4">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username" />
</div>
</div>
<div class="form-group row">
<label for="password" class="col-2 col-form-label">Password</label>
<div class="col-4">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password" />
</div>
</div>
<div class="form-group row">
<div class="col-2"></div>
<div class="col-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-6">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
I want the form to be centered on the page, but instead, it's still further to the left than center as shown by this screenshot:
I thought my math was correct: Bootstrap uses a 12-column grid, so by using a 3-column offset, and a 6-column content area, I'd have essentially two 3-column gutters on each side. And by specifying the form rows to add up to 6-columns (2-column labels and 4-column inputs), the form would fill the 6-column content area, thereby automatically centering itself. But I'm obviously wrong.
So, what can I do to actually center this thing? And to make it 6 columns wide (because, judging by the screenshot, it isn't)?
The form is horizontally centered, but it's only half the width of it's parent. The issue is...
"And by specifying the form rows to add up to 6-columns (2-column
labels and 4-column inputs), the form would fill the 6-column content
area, thereby automatically centering itself"
Since 6 is half of 12, the form col-6 (2+4) is only going to fill half the parent col-6. If you want a narrower form in the middle use col-4 (1/3 width), and then something that adds to 12 for the labels and form input (eg. 3+9). OFC you could also use 4/8, 6/6, etc...
<div class="container-fluid">
<div class="row">
<div class="my-4 offset-4 col-4 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-3 col-form-label">Username</label>
<div class="col-9">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-3 col-form-label">Password</label>
<div class="col-9">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<div class="col-3"></div>
<div class="col-9">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on">
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
https://www.codeply.com/go/b4FE5qflxS
Related: Center the content inside a column in Bootstrap 4
You can accomplish this by using col-6 and justify-content-center. All you have to do is setup the elements, rows and columns with bootstrap.
Here is an example of centering the form group:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="site" class="container-fluid">
<div class="row justify-content-center">
<div class="col-6" style="background: #eee;">
<!-- formgroup start -->
<form>
<div action="/some/path" class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Enter username" name="_username" required="required" autocomplete="username" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" name="_password" required="required" autocomplete="current-password" />
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="remember_me" name="_remember_me" value="on" />
<label class="form-check-label" for="remember_me">Remember me</label>
</div>
<button type="submit" class="btn btn-primary" id="_submit" name="_submit">Submit</button>
</form>
<!-- formgroup end -->
</div>
</div>
</div>
Reference these pages on the Bootstrap 4 documentation
https://getbootstrap.com/docs/4.1/layout/grid/
https://getbootstrap.com/docs/4.1/components/forms/

Bootstrap formatting columns align issue

Working html code: UPDATED
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>
<form class="form-horizontal ng-pristine ng-valid ng-valid-required" role="search">
<div class="row">
<div class="form-group col-md-12">
<label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
<div class="col-md-4">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
</div>
<div class="col-md-2">
<button class="form-control btn btn-info">Hello world</button>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
<div class="col-md-6">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
</div>
</div>
</div>
</form>
How can I format my lable/input field align? below is html along with screen shots how it renders after I run the page:
what I want the output to be is:
Employee Name: XXXXXXXXXXXXX
My Owning Location: XXXXXXXXXXXXX
Manager Name: XXXXXXXXXXXXX
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>
<form class="navbar-form form-horizontal ng-pristine ng-valid ng-valid-required" role="search" style="padding:0">
<div class="col-md-12" style="margin: 10px;">
<div class="form-group">
<label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
<div class="col-lg-6">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
</div>
</div>
</div>
<div class="col-md-12" style="margin: 10px;">
<div class="form-group">
<label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
<div class="col-lg-6">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
</div>
</div>
</div>
</form>
I've solved this for you and created a codepen editor for this.
The code will look lke,
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" rel="stylesheet"/>
<form class="form-horizontal ng-pristine ng-valid ng-valid-required" role="search">
<div class="row">
<div class="form-group col-md-12">
<label class="control-label col-md-6" for="inputEmail">Employee Name:</label>
<div class="col-md-6">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="control-label col-md-6" for="inputEmail">My Owning Location:</label>
<div class="col-md-6">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
</div>
</div>
</div>
</form>
What I've done is wrap your form group elements into row classes which makes children appear in a row, and for the form-group classed element I've set it to col-md-12 which does make it full width of the grid.
I've also removed navbar-form class from your form element
I've heard my colleague (front-end guy) saying to use row and child elements of them as grid columns as a standard, i don't know the validity of that statement, but it works for real! :)
And a note, do not use inline styles which makes things lot worse and untraceable while looking at the code itself.
I added the corresponding row-fluid to reset the grid for the label and input boxes.
https://jsfiddle.net/gyod/7mgtfk3k/4/ Here is one example.
<form class="container row-fluid navbar-form form-horizontal ng-pristine ng-valid ng-valid-required" role="search" style="padding:0">
<div class="col-md-12" style="margin: 10px;">
<div class="row-fluid">
<label class="control-label col-xs-3" for="inputEmail">Employee Name:</label>
<div class="col-xs-9">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="John Edward Jr.">
</div>
</div>
</div>
<div class="col-md-12" style="margin: 10px;">
<div class="row-fluid">
<label class="control-label col-xs-3" for="inputEmail">My Owning Location:</label>
<div class="col-xs-9">
<input class="form-control" disabled="disabled" id="inputEmail" type="email" value="abc123 234sd 343 scott 359 to-34-23-3">
</div>
</div>
</div>
</form>
Try to put the label tag inside div class="col-xs-6". Then you can get a horizontal aligned elements of each div.
If you want to make it properly align, you can set default width for the label and use bootstrap built-in class for alignment.

Using Bootstrap, how do I position labels to the left of the input box when there are multiple inputs on the same row

I have a row with three inputs, two of the inputs have labels to their left. What is happening is the label is being displayed on top of the input box rather than to the side, like so:
Here is what I am trying to achieve:
<div class="row">
<div data-bind="foreach: items" class="padding-left-lg">
<div class="col-sm-4">
<input type="text" data-bind="value: Description,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
<div class="col-sm-4">
<label class="control-label">
Quantity: <input type="text" data-bind="value: Quantity,valueUpdate: 'afterkeydown'" class="form-control"/>
</label>
</div>
<div class="col-sm-1">
<input type="text" data-bind="value: Units,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
</div>
</div>
I would try something like this:
<form class="row form-horizontal">
<div class="col-sm-5">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</div>
</form>
Here is the fiddle I made https://jsfiddle.net/g3e8yjyg/.
What is different from the default Bootstrap example? You treat your form as a row or a set of rows, and each formgroup becomes a cell, where you will only vary the value of the size. This will allow you to put many fields in a single row.
<form class="row">
<!--Columns -->
<div class="col-lg-*">
<!--Your form group in here -->
<div class="form-group">
<!--The elements of you formgroup treated as col divs-->
<label for="inputPassword3" class="col-lg-*">Your label</label>
<div class="col-lg-*">
<input name="my-input">
</div>
</div>
</div>
<!--Columns -->
<div class="col-lg-*">
...
</div>
</form>
Add the form-inline class to your form, add the form-group class to the containing div, and move the input tag out of your label tag:
<form class="form-inline">
<div class="form-group col-sm-4">
<label class="control-label">Quantity:</label>
<input type="text" data-bind="value: Quantity,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
</div>

Bootstrap input fields are not the same width when putting them in separate columns

I have created a form for online admissions using the Bootstrap framework. I am having a problem with putting two input fields in separate columns; those two fields are not adjusted according to the other fields' width. Here is my form code and also image of this problem:
<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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<form method="post" action="">
<h3>Personal Information</h3>
<div class="form-group">
<span>Name</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<div class="form-group">
<span>Father Name</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<div class="form-group">
<div class="col-xs-6">
<span>Nationality</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<div class="col-xs-6">
<span>Region</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<span>Date of Birth</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<div class="col-xs-6">
<span>Place of Birth</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<h3></h3>
</div>
<div class="form-group">
<span>Permanent Home Address</span>
<span><input type="username" class="form-control" id="userName"></span>
</div>
<div class="form-group">
<span>e-mail</span>
<span><input type="email" class="form-control" id="inputEmail3"></span>
</div>
<div>
<label class="fa-btn btn-1 btn-1e"><input type="submit" value="submit us"></label>
</div>
</form>
Use Bootstrap's predefined grid classes to align labels and groups of form controls in a horizontal layout by adding .form-horizontal to the form (which doesn't have to be a ). Doing so changes .form-groups to behave as grid rows, so no need for .row.
HTML
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
To be using the boostrap form grid system correctly, you just need to warp the content of your first two inputs in a .col-xs-12 class.
Like this:
<div class="form-group">
<div class="col-xs-12">
<span>Name</span>
<span><input type="username" class="form-control" id="userName">
</span>
</div>
</div>
col-xs-6 is adding the padding. You can wrap your groups in col-xs-12, or add a col-xs-12 to each form group which should be full width.
Here is my plunker
Working demo
Wrap the form-groups in a <div class="row"></div>. This will remove the padding added by the col-xs-6 classes.