How to include the glyphicon within input field? - html

Created a form for user input by making use of Bootstrap classes. I have included the simple form inclusion for your perusal.
Issue:
1.) I am trying to place the glyphicon within the input box of the form, however the icon is placed outside. I have called the glyphicon glyohicon-date within the input tag class but the icon is placed outside of the input box. How is it possible for me to input it inside the input box?
Thanks.
<div class="row row-content">
<div class="col-xs-12 col-lg-3">
<p style="padding:20px;"></p>
<h3 align=center>Reserve A Table</h3>
</div>
<div class="col-xs-12 col-sm-9">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">Number of Guests</label>
<div class="input-group col-sm-4">
<input type="radio">
<span> 1 </span>
<input type="radio">
<span> 2 </span>
<input type="radio">
<span> 3 </span>
<input type="radio">
<span> 4 </span>
<input type="radio">
<span> 5 </span>
<input type="radio">
<span> 6 </span>
</div>
</div>
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">Date & Time</label>
<div class="col-sm-4">
<input type="text" class="form-control glyphicon glyphicon-calendar" aria-hidden="true" id="Date" name="Date" placeholder="Date"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
</div>
<div class="col-sm-4">
<input type="text" class="form-control glyphicon glyphicon-time" id="Time" name="Time" placeholder="Time">
</div>
</div>
<button type="submit" class="btn btn-default">Reserve</button>
</form>
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<strong>Warning!</strong> Please <strong>call</strong> us to reserve for more than six guests.
</div>
</div>
</div>

Have managed to solve it from the given link: With optional icons
<div class="form-group has-feedback">
<label for="firstname" class="col-sm-2 control-label">Date & Time</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="Date" name="Date" placeholder="Date">
<span class="glyphicon glyphicon-calendar form-control-feedback" aria-hidden="true"></span>
</div>
<div class="col-sm-4">
<input type="text" class="form-control" id="Time" name="Time" placeholder="Time">
<span class="glyphicon glyphicon-time form-control-feedback" aria-hidden="true"></span>
</div>
</div>

<div class="form-group form-inline">
<label for="datetime" class="col-sm-2 control-label">Date and Time</label>
<div class="col-sm-5">
<div class="form-group has-feedback">
<input type="text" class="form-control" id="datetime" name="datetime" placeholder="Date">
<i class="glyphicon glyphicon-calendar form-control-feedback"></i>
</div>
</div>
<div class="col-sm-5">
<div class="form-group has-feedback">
<input type="text" class="form-control" id="datetime" name="datetime" placeholder="Time">
<i class="glyphicon glyphicon-time form-control-feedback"></i>
</div>
</div>
</div>

This is a coursera assignment of Bootstrap
using the "With optional icons" method in Bootstrap you can achieve this:
for example, my answer to this question:
<div class="form-group has-feedback">
<label class="col-sm-2 control-label" for="date-choose">Date and Time</label>
<div class="col-sm-5">
<input type="date" class="form-control" id="date-choose" placeholder="Date">
<i class="glyphicon glyphicon-calendar form-control-feedback" aria-hidden="true"></i>
</div>
</div>
you can refer to the link below to find what you want:
http://getbootstrap.com/css/#forms-control-validation
The one more thing you have to know is that this only adds the icon to the input box but not changes the default action of the JavaScript behind it, so the icon you are adding has no response unless you change the default event of this input box.

Related

Modal background not extending

I am having a very strange occurrence when running this Modal as seen below:
<button type="button" class="btn btn-primary btn-md" data-toggle="modal" data-target="#reserveModal">
Read more »
</button>
<div id="reserveModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form class="form-inline" role="form" id="reservations">
<div class="form-group col-xs-12" style=" margin:10px">
<label for="guests" class="col-xs-3 control-label">
<h4>Number of Guests</h4></label>
<div class="checkbox col-xs-9" id="guests">
<label class="checkbox-inline margin:0 px">
<input type="radio" name="approve" value="">
<strong>1</strong>
</label>
<label class="checkbox-inline">
<input type="radio" name="approve" value="">
<strong>2</strong>
</label>
<label class="checkbox-inline">
<input type="radio" name="approve" value="">
<strong>3</strong>
</label>
<label class="checkbox-inline">
<input type="radio" name="approve" value="">
<strong>4</strong>
</label>
<label class="checkbox-inline">
<input type="radio" name="approve" value="">
<strong> 5 </strong>
</label>
<label class="checkbox-inline">
<input type="radio" name="approve" value="">
<strong> 6 </strong>
</label>
</div>
</div>
<div class="form-group col-xs-12" style=" margin:10px">
<label for="section" class="col-xs-3 control-label">
<h4>Section</h4></label>
<div class="section col-xs-9" id="section">
<input type="radio" name="section" value="" id="nonSmoking">
<label class="nonSmoking checkbox-inline" for="nonSmoking">
<strong>Non-Smoking</strong>
</label>
<input type="radio" name="section" value="" id="smoking">
<label class="smoking checkbox-inline" for="smoking">
<strong>Smoking</strong>
</label>
</div>
</div>
<div class="form-group col-xs-12" style=" margin:10px">
<label for="date time" class="col-xs-3 control-label text-align:right">
<h4>Date and Time</h4></label>
<div class="input-group add-on date datepicker form col-xs-3">
<input type="date" class="form-control date-picker" id="date" />
<div class="input-group-btn">
<button class="btn btn-default">
<i class="fa fa-calendar"></i>
</button>
</div>
</div>
<div class="input-group form col-xs-2 col-xs-offset-1">
<input type="time" class="form-control" id="time" placeholder="Time" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
<div class="col-xs-12" margin:10px>
<button type="submit" class="btn btn-primary col-xs-offset-3">Reserve</button>
</div>
</form>
</div>
<!-- /.modal-body -->
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
For context, I am going through a Coursera class and this is part of one of the assignments. I cannot figure out why the background does not cover the entirety of the modal - only covering the top line or so.
Here is the jsfiddle: https://jsfiddle.net/jacoblhughes/y55uyhfx/2/
Add clearfix class to <form class="form-inline" role="form" id="reservations">
Since you're using col-xs-12 on the form-group items, they're floated to the left, thus the parent form doesn't take on their height. So you need to apply the clearfix to it. If you don't know what clearfix is, I would suggest looking it up.

Bootstrap inline form with labels above input

I want to create an inline form using bootstrap with labels above input text fields but the result looks so messed up.
This is what i tried:
<form id="form" method="post" class="form-inline" >
<div class="row">
<div class="col-md-2">
<label for="from">from:</label>
<input type="text" class="form-control form-text" />
</div>
<div class="col-md-2">
<label for="to">to:</label>
<input type="text" class="form-control form-text"/>
</div>
<div class="input-group date col-md-2" id="datepicker">
<label for="checkin">check in</label>
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
<div class="input-group date col-md-2" id="datepicker">
<label for="checkout">check out</label>
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-default" value="submit"/>
</div>
</div>
</form>
this is what i got:
result
how do i get the submit button to right position and the glyphicons heights the same as the input fields what am i doing wrong?
I made some edits to your html : https://jsfiddle.net/05t4s041/
<form id="form" method="post" class="form-inline" >
<div class="row">
<div class="col-md-2">
<label for="from">from:</label>
<input type="text" class="form-control form-text" />
</div>
<div class="col-md-2">
<label for="to">to:</label>
<input type="text" class="form-control form-text"/>
</div>
<div class="col-md-2">
<label for="checkin">check in</label>
<div class="input-group date" id="datepicker">
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
</div>
<div class="col-md-2">
<label for="checkout">check out</label>
<div class="input-group date" id="datepicker">
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-default" value="submit"/>
</div>
</div>
</form>
you could put divs with bootstrap classes around your label and control like:
<div class="col-md-2">
<div class="row">
<div class="col-md-6">
<label for="from">from:</label>
</div>
<div class ="col-md-6">
<input type="text" class="form-control form-text" />
</div>
</div>
</div>
The row div may be sufficient: it put's elements in a row put I like to put extra bootstrap classes around my controls so I can modify them. For example that the label has a smaller width than the control itself.

How to move to down of the page using button in bootstrap

I am trying to add button on top of the page and one form at the bottom when I click on the button it should go down at the form location on same page. I am don't know how I can do that.
here is my code for button
<div class="col-xs-12 col-sm-2">
<p style="padding:40px;"></p>
<button class="btn btn-block btn-warning">Reserve Table</button>
</div>
Here is my code of form
<div class="col-xs-6 col-sm-3">
<div class="form-vertical" role="form">
<p style="padding:10px;"></p>
<h3>Table Reservation</h3>
</div>
</div>
<div class="col-xs-6 col-sm-9">
<div class="form-horizontal" role="form">
<div class="form-group">
<label for="Number" class="col-sm-2 control-label">Number of people</label>
<label class="radio-inline">
<input type="radio" name="optradio">1
</label>
<label class="radio-inline">
<input type="radio" name="optradio">2
</label>
<label class="radio-inline">
<input type="radio" name="optradio">3
</label>
<label class="radio-inline">
<input type="radio" name="optradio">4
</label>
<label class="radio-inline">
<input type="radio" name="optradio">5
</label>
<label class="radio-inline">
<input type="radio" name="optradio">6
</label>
</div>
<div class="form-group has-feedback">
<label for="Date-time" class="col-sm-2 control-label">Date & Time</label>
<div class="col-sm-3">
<input type="text" class="form-control pull-left" name="Date-time" placeholder="date">
<i class="glyphicon glyphicon-calendar form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="time">
<i class="glyphicon glyphicon-time form-control-feedback"></i>
</div>
</div>
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
Please <strong >call</strong> for bookinng of more than 6 people.
</div>
</div>
</div>
please tell me how to do this??
Hello #lomesh shah this is easy.
Step 1
First give that form an id like
<form id="testform"> rest of the code goes here </form>
Step 2
You have to use anchor tag instead of the button but by using bootstrap's btn classes over it you can give it a button apperance and then use id of the form inside the href, click which will take you down to the form. See code below
Go to form
Confusion ? Hit me back :) I will respond
give the form id
then use this
Reserve Table</button>

decrease input width (using bootstrap)

I am trying to decrease middle name input field but i can't get it work. It only works at xs screen (picture below).
<div class="row">
<form class="form-inline" role="form" name="userForm" novalidate>
<div class="form-group required">
<label for="first" class="control-label">Child's Name</label>
<div class="input-group">
<span class="col-xs-9 col-sm-5">
<input type="text" class="form-control" id='first' name="first" >
<label for ="first">First </label>
</span>
</div>
<div class="input-group">
<span class="col-xs-3 col-sm-2">
<input type="text" class="form-control col-xs-3 col-sm-2" id='mi' name="mi" >
<label for ="mi">MI</label>
</span>
</div>
<div class="input-group">
<span class="col-xs-9 col-sm-5">
<input type="text" class="form-control" id = "last" name="last" >
<label for="last"> Last </label>
</span>
</div>
</div>
</form>
</div>
You're code is wrong please check again.you end the </form> before end other tag. and again read how to use bootstrap form. help this link.
remove span and add col-sm-4 to div
`
<div class="form-group required">
<label for="first" class="control-label">Child's Name</label>
<div class="input-group col-sm-4">
<input type="text" class="form-control" id='first' name="first">
<label for="first">First </label>
</div>
<div class="input-group col-sm-1">
<input type="text" class="form-control " id='mi' name="mi">
<label for="mi">MI</label>
</div>
<div class="input-group col-sm-4">
<input type="text" class="form-control " id="last" name="last">
<label for="last"> Last </label>
</div>
<div class="help-block" ng-messages="userForm.first.$error" style="color:maroon" role="alert">
<p ng-message="required">Child's First Name is required.</p>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>`

Fixed length of span size in input form

I have a form with some input tags and for each of it(I'm using bootstrap). I would like to use span with backgroud coloro but I have a problem with the size of it, because depends of text length (the best way is to use awesome, but I don't find icons useful to my purpose).
Is there a way to fix the width of the grey part of div? I tried with width, like the image, but it resize all the input fields.Thanks
<div class="row">
<!-- Fleet fields -->
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-car fa-fw"></i> Fleet inputs
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<form role="form">
<div class="form-group input-group">
<span class="input-group-addon">Ap</span> <input type="text"
class="form-control" placeholder="Application">
</div>
<div class="form-group input-group">
<input type="text" class="form-control" placeholder="Cubic">
<span class="input-group-addon">cm<sup>3</sup></span>
</div>
<div class="form-group input-group">
<input type="number" class="form-control" placeholder="Power">
<span class="input-group-addon">H P</span>
</div>
<div class="form-group input-group">
<span class="input-group-addon">Eu</span> <input type="text"
class="form-control" placeholder="Euro class">
</div>
<div class="form-group input-group">
<span class="input-group-addon">Et</span> <input type="text"
class="form-control" placeholder="Engine type">
</div>
<div class="form-group input-group">
<span class="input-group-addon">Tr</span> <input type="text"
class="form-control" placeholder="Traction">
</div>
<div class="form-group input-group">
<span class="input-group-addon">Ts</span> <input type="text"
class="form-control" placeholder="Transmission">
</div>
<div class="form-group">
<label>Note</label>
<textarea class="form-control" rows="2" maxlength="100"></textarea>
</div>
</form>
</div>
<!-- /.panel-body -->
</div>
</div>
Css of input -group-addon
.input-group-addon{color:#3c763d;background-color:#dff0d8;border-color:#3c763d}
you can use for fixed width of grey part of div
you can use for fixed width of grey part of div
1.<div class="input-group input-group-lg"> <span class="input-group-addon" id="sizing-addon3">#</span> <input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon3"> </div>
2. can use also another div <div class="input-group input-group-sm">
3. can use also <div class="input-group">
for the Icon you can use Class="fa fa-edit" or Class="glyphicon glyphicon-pencil"
for the Icon you can use Class="fa fa-edit" or Class="glyphicon glyphicon-pencil"