Create an inline form with input-groups bootstrap - html

I'm trying to create a simple inline form using input groups to display icons before the inputs. As far as I'm aware of I'm following the documentation but the form doesn't display as expected. See this JSFiddle, it demonstrates the problem. I assumed it should be displayed like this (only with the icons prepended of course). How can this be solved?
My code:
<form class="form-inline" role="form">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input type="email" class="form-control" placeholder="Enter email"/>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input type="password" class="form-control" placeholder="Choose password"/>
</div>
</div>
<button type="submit" class="btn btn-default">Create account</button>
</form>

This is known issue and will be fixed in Bootstrap v.3.2.0 according to this ship list.
Before that you can fix it your self like this:
.input-group {
display: inline-table;
vertical-align: middle;
.input-group-addon,
.input-group-btn,
.form-control {
width: auto !important;
}
}

i've made it work like this:
<form class="form-inline" role="form">
<div class="row">
<div class="form-group col-sm-3">
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input type="email" class="form-control" placeholder="Enter email" />
</div>
</div>
<div class="form-group col-sm-3">
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input type="password" class="form-control" placeholder="Choose password" />
</div>
</div>
<button type="submit" class="btn btn-default">Create account</button>
</div>
http://jsfiddle.net/n5qmc/

Taken from Bootstrap Docs
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. Doing so changes .form-groups to behave as grid rows, so no need for .row.
I also added in semantic attributes for the labels you should always be using on every input (use .sr-only to hide the labels if necessary). This makes the form not inline but horizontal.
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<div class="input-group col-sm-3">
<span class="input-group-addon">
<i class="fa fa-envelope-o fa-fw"></i>
</span>
<input type="email" id="email" name="email" class="form-control" placeholder="Enter email" />
</div>
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<div class="input-group col-sm-3">
<span class="input-group-addon">
<i class="fa fa-key fa-fw"></i>
</span>
<input type="password" id="password" name="password" class="form-control" placeholder="Choose password" />
</div>
</div>
<button type="submit" class="btn btn-default">Create account</button>
</form>

Not sure if this is helpful, but I thought I would post as I haven't seen this elsewhere. I was trying to get an inline form with inline labels and an add-on using Bootstrap v3. Here is the code that worked for me. I used the grid system in divs to position the label and input group and the add-on within a grid item.
<div class="form-group">
<div class="col-sm-2">
<label class="control-label" for="input_one">Label Text</label>
</div>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" placeholder="Placeholder Text" type="text" name="input_one" id="input_one">
<span class="input-group-addon">Add on text</span>
</div>
</div>
</div>

Related

how to make two elements to be in the same line - html css

I have this code:
<div class="{{($type != 'forecast')?'col-md-8':'col-md-8'}}">
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control" name="name" value="12" {{($viewOnly)?'disabled':''}} >
<i class="fa fa-info-circle" title="test"></i>
</div>
</div>
this is the UI
I just want the <i> icon be next to the input field and not in the bottom.
How I can achieve that?
Wrap the input field and the icon within a div with the class input-group.
<div class="input-group">
<input type="text" class="form-control" name="name" value="12" {{($viewOnly)?'disabled':''}}>
<i class="fa fa-info-circle" title="test"></i>
</div>
this is the solution
<div class="form-group">
<label>Name:</label>
<div class="input-group" style="display: flex">
<input type="text" class="form-control" name="name" value="12" {{($viewOnly)?'disabled':''}} >
<i class="fa fa-info-circle" title="test"></i>
</div>
</div>

Parsley js breaks the glyphicon alignment on validation error

I have a password input box which contains a glyphicon info image on the right side. I am using parsley.js to validate this input box. On form submit if password validation fails parsley displays the error message beneath the input box as expected but also breaks the alignment of the glyphicon icon and makes it protrude out of the input box. Please find jsfiddle demo here
https://jsfiddle.net/bsbef0qd/2/ . Thanks
<form id="form" data-parsley-validate="">
<div class="row">
<div class="col-xs-4">
<label for="password" class="control-label">Password</label>
<div class="input-group add-on">
<input type="password" name="userFormPassword" id="userFormPassword" value="" class="form-control input-sm" required/>
<span class="input-group-addon">
<a class='my-tool-tip' data-toggle="tooltip" data-placement="left" title="Some password instructions">
<i class='glyphicon glyphicon-info-sign'></i>
</a>
</span>
</div>
</div>
<div class="form-group col-xs-4">
<label for="confirm" class="control-label">Confirm Password</label>
<input type="password" name="confirm" value="" class="form-control input-sm" />
</div>
</div>
<button type="submit">Submit</button>
</form>
You can change the error displaying position..
Add this part to your form tag as a attribute "data-parsley-errors-container="#errorContainer""
<form id="form" data-parsley-validate="" data-parsley-errors-container="#errorContainer">
put this div to where you want the errors to display
<div id="errorContainer"></div>
I have edited your fiddle check the demo
Also Check the Plugin documentation here
also, you can use data-parsley-errors-container="#your-div-id" in your input element
<div class="form-group">
<label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Start Time</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class=" datetimepicker3 input-append timepick">
<input class="form-control" data-format="hh:mm" placeholder="HH:MM" type="text" name="startTime" data-parsley-errors-container="#startTimeErrorContainer" required="required" id="startTime" />
<span class="add-on"><i class="fa fa-clock-o icon-time"></i></span>
</div>
<div id="startTimeErrorContainer"></div>
</div>

Bootstrap class "form-inline" Break inside div

I´m trying to stop/break the form-inline class inside just one div.
I have three input fields.
I´d like the two first one left side, ontop of each other.
And the third on the rigth side of them.
check Fiddle
https://jsfiddle.net/rjc5s1vn/
This is a pretty large form, so i don´t like to remove form-inline from the parent form.
HTML
<form class="form-inline well col-md-10">
<!-- Produkt input-->
<div class="input-group col-md-4 form">
<div class="input-group-addon"><i class="glyphicon glyphicon-wrench"></i></div>
<input id="produkt" name="produkt" type="text" placeholder="Produkt" class="form-control input-sm">
<br>
<div class="input-group-addon"><i class="glyphicon glyphicon-transfer"></i></div>
<input id="objekt_lev_dat" name="objekt_lev_dat" type="text" placeholder="Leverans datum" class="form-control input-sm" required>
</div>
<!-- Adress Textarea -->
<div class="input-group col-md-4">
<div class="input-group-addon"><i class="fa fa-truck"></i></div>
<textarea class="form-control" id="objekt_mont_adress" name="objekt_mont_adress" rows="3" placeholder="Adress" required> </textarea>
</div>
</form>
Try the following: https://jsfiddle.net/rjc5s1vn/3/
I wrapped your inputs and glyphicons pairings into two wrapping <div class="test">:
<form class="form-inline well col-md-10">
<!-- Produkt input-->
<div class="input-group col-md-4 form">
<div class="test">
<div class="input-group-addon"><i class="glyphicon glyphicon-wrench"></i></div>
<input id="produkt" name="produkt" type="text" placeholder="Produkt" class="form-control input-sm">
</div>
<br>
<div class="test">
<div class="input-group-addon"><i class="glyphicon glyphicon-transfer"></i></div>
<input id="objekt_lev_dat" name="objekt_lev_dat" type="text" placeholder="Leverans datum" class="form-control input-sm" required>
</div>
</div>
<!-- Adress Textarea -->
<div class="input-group col-md-4">
<div class="input-group-addon"><i class="fa fa-truck"></i></div>
<textarea class="form-control" id="objekt_mont_adress" name="objekt_mont_adress" rows="3" placeholder="Adress" required></textarea>
</div>
</form>
CSS:
.form-inline > .input-group:first-child > .test {
display: block;
}
.form-inline > .input-group:first-child > .test div, .form-inline > .input-group:first-child > .test input {
display: inline-block;
float: left;
}
I solved it like this:<br>
Notice more nestled <div><br>
<!-- Product input-->
<div class="col-md-4" style="padding-left: 0px">
<div class="input-group input-group-sm col-md-12">
<div class="input-group-addon"><i class="glyphicon glyphicon-wrench"></i></div>
<input id="produkt" name="produkt" type="text" placeholder="Produkt" class="form-control">
</div>
<br>
<div class="input-group input-group-sm col-md-12">
<div class="input-group-addon"><i class="glyphicon glyphicon-transfer"></i></div>
<input id="objekt_lev_dat" name="objekt_lev_dat" type="text" placeholder="Leverans datum" class="form-control" required>
</div>
</div>
I have a solution. You can try by this way. I just used core bootstrap and some css. Have a look on my demo
<form class="form-inline well col-md-10">
<div class="item">
<div class="input-group input-group-sm input_item">
<span class="input-group-addon" id="sizing-addon1">#</span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon1">
</div>
<div class="input-group input-group-sm input_item">
<span class="input-group-addon" id="sizing-addon1">#</span>
<textarea class="form-control" placeholder="Username" aria-describedby="sizing-addon1"></textarea>
</div>
<div class="input-group input-group-sm input_item">
<span class="input-group-addon" id="sizing-addon1">#</span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon1">
</div>
<div class="clearfix">
</div>
</div>
</form>
.form-inline .item .input_item{
width:calc(50% - 7.5px);
margin-bottom:15px;
}
.form-inline .item .input_item textarea{
min-height:75px;
}
.form-inline .item .input_item:first-child{
float:left;
}
.form-inline .item .input_item:nth-child(2){
float:right;
}
.form-inline .item .input_item:last-child{
float:left;
}
Try out this
<form class="form-inline">
<div class="input-group col-md-4 form">
<div class="input-group-addon"><i class="glyphicon glyphicon-wrench"></i></div>
<input id="produkt" name="produkt" type="text" placeholder="Produkt" class="form-control input-sm">
<br></div>
<div class="input-group col-md-4 form">
<div class="input-group-addon"><i class="glyphicon glyphicon-transfer"></i></div>
<input id="objekt_lev_dat" name="objekt_lev_dat" type="text" placeholder="Leverans datum" class="form-control input-sm" required>
</div>
<div class="input-group col-md-4">
<div class="input-group-addon"><i class="fa fa-truck"></i></div>
<textarea class="form-control" id="objekt_mont_adress" name="objekt_mont_adress" rows="3" placeholder="Adress" required></textarea>
</div>
</form>
See Demo

Bootstrap 3- Inline forms are not aligning properly in Chrome

I am using the following code for my inline form (bootstrap 3) but that doesn't seem to work with Google Chrome. I tried it with Firefox and it worked great. Screenshots:
Chrome
http://oi58.tinypic.com/148jjw5.jpg
Firefox
http://oi58.tinypic.com/5fiy41.jpg
The HTML and CSS I'm using:
<style>
.form-inline .form-group {
margin-right: 10px;
margin-left: 4px;
}
.form-inline > .form-group {
vertical-align: top;
}
</style>
<form id="callForm" action="sendCall.php" method="post" class="form-inline" >
<div class="form-group col-md-2">
<div class="input-group">
<label class="sr-only" for="your">Your phone number</label>
<span class="input-group-addon">+91</span>
<input type="text" class="form-control" id="your" name="your" placeholder="Your 10 digit number" required />
</div>
</div>
<div class="form-group col-md-2">
<div class="input-group">
<label class="sr-only" for="frnd">Friend's number</label>
<span class="input-group-addon">+</span>
<input text="text" class="form-control" id="frnd" name="frnd" placeholder="Your friend's number" required />
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Connet</button>
</div>
</form>
<script>
You should not put your sr-only element inside the input-group:
<div class="form-group col-md-2">
<label class="sr-only" for="your">Your phone number</label>
<div class="input-group">
<span class="input-group-addon">+91</span>
<input type="text" class="form-control" id="your" name="your" placeholder="Your 10 digit number" required />
</div>
</div>
Anyway, if this fix an extra border (and maybe a floating issue), I doubt this is the only thing to change.
You may have another CSS rule which broke your layout.
For me its working fine on both browser, may be your CSS is not working properly or you are using the old version CSS.
check your css or may be some other properties are overwriting your css that could be the problm.
their is no problem in this code.
<form class="form-inline" >
<div class="form-group col-md-2">
<div class="input-group">
<label class="sr-only" for="frnd">Friend's number</label>
<span class="input-group-addon">+</span>
<input text="text" class="form-control" id="frnd" name="frnd" placeholder="Your friend's number" required />
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Connet</button>
</div>
</form>

Bootstrap 3: Set custom width with input-group/input-group-addon and horizontal labels

I would like to control the size of my input elements using the class .col-lg-* outlined here on the bootstrap website. However, putting the <span> element inside of a div completely messes it up:
HTML with div:
<div class="input-group input-group-lg">
<label for="" class="control-label">Paycheck</label>
<div class="col-lg-10">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" id="">
</div>
</div>
How can I set the width of the input elements so that they are all the same?
I want the left margin of each input element to be flush like so:
This is what it looks like now:
This is my current HTML:
<div class="col-md-6">
<div class="content">
<h2>Income</h2>
<form class="form-income form-horizontal" role="form">
<div class="input-group input-group-lg">
<label for="" class="control-label">Paycheck</label>
<span class="input-group-addon">$</span>
<input type="text" class="form-control" id="">
</div>
<div class="input-group input-group-lg">
<label for="" class="control-label">Investments</label>
<span class="input-group-addon">$</span>
<input type="text" class="form-control" id="">
</div>
<div class="input-group input-group-lg">
<label for="" class="control-label">Other</label>
<span class="input-group-addon">$</span>
<input type="text" class="form-control" id="">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Update</button>
</form>
</div>
LIVE EXAMPLE: http://jsfiddle.net/jfXUr/
As per my comment above, try grouping the label and .input-group together with a .form-group container.
<div class="form-group">
<label for="" class="control-label">Paycheck</label>
<div class="input-group input-group-lg">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" id="">
</div>
</div>
Demo here - http://jsfiddle.net/jfXUr/1/