Is it possible to insert a form with select element inside horizontal form in Bootstrap.
I need to insert a form with select element inside form group.
Bootply code here
Note: Bootply messes the code and remove some form tags, so copy the code below.
The problem the element becomes not aligned. The two selects for Country and Language in the code not aligned and messes the code after them.
The code is here again:
<div class="container-fluid">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-4 control-label" for="fname">First name:</label>
<div class="col-sm-8">
<input class="form-control" name="fname" id="fname" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="lname">Last name:</label>
<div class="col-sm-8">
<input class="form-control" name="lname" id="lname" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="country">Country:</label>
<div class="col-sm-8">
<form>
<select name="country" id="country" class="form-control">
<option value="US">US</option>
<option value="UK">UK</option>
<option value="CA">CA</option>
</select>
</form>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="language">Language:</label>
<div class="col-sm-8">
<form>
<select name="language" id="language" class="form-control">
<option value="en-US">en-US</option>
<option value="en-UK">en-UK</option>
<option value="fr">FR</option>
</select>
</form>
</div>
</div>
</form>
</div>
You have multiple <form></form> values in your code. Since this is only one form all you need is the form class at the beginning and the close at the end. This is why it's becoming misaligned. Check out my fiddle
http://jsfiddle.net/jxe78828/
According to the HTML5 specs, you can't nest one form inside another:
4.10.3 The form element
...
Content model:
Flow content, but with no form element descendants.
Bootstrap is designed with the assumption that you will be using valid HTML structure. So you may want to rethink your HTML structure and if there is another way to accomplish what you are trying to do with nested <form> elements.
Try this:
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-4 control-label" for="fname">First name:</label>
<div class="col-sm-8">
<input class="form-control" name="fname" id="fname" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="lname">Last name:</label>
<div class="col-sm-8">
<input class="form-control" name="lname" id="lname" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="country">Country:</label>
<div class="col-sm-8">
<select name="country" id="country" class="form-control">
<option value="US">US</option>
<option value="UK">UK</option>
<option value="CA">CA</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="language">Language:</label>
<div class="col-sm-8">
<select name="language" id="language" class="form-control">
<option value="en-US">en-US</option>
<option value="en-UK">en-UK</option>
<option value="fr">FR</option>
</select>
</div>
</div>
</form>
</div>
You can also see my JSFiddle here
After a lot of search with people answering without reading the question clearly and misunderstanding what I need. Clearly the question means I need separate forms or sub forms inside forms, this can be possible with HTML 5 attribute form in this way:
<select name="country" id="country" class="form-control" form="country-form">
where you can just put empty form any where like this:
<form id="country-form"></form>
or even this form does not exist, the above form field will not be included anyway when submitting the container form.
Related
I am quite new to bootstrap, I have build the following form, but I want to know if someone can please assist me and help me make this form more inline as I think from a layout perspective there is a better way out there, but I really do not know how to achieve it, I will appreciate all the help.
Essentially help me make my form more aesthetically pleasing.
HTML:
<!-- Form Name -->
<legend>Order Form</legend>
<form class="form-horizontal form-shadow">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">E-mail</label>
<div class="col-md-4">
<input id="email" name="email" type="text" placeholder="Enter E-mail" class="form-control input-md" required="">
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="tile">Select Title</label>
<div class="col-md-4">
<select id="tile" name="tile" class="form-control">
<option value="Miss">Miss</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
<option value="Rev">Rev</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="Enter Name" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="surname">Surname</label>
<div class="col-md-4">
<input id="surname" name="surname" type="text" placeholder="Enter Surname" class="form-control input-md" required="">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="address">Address</label>
<div class="col-md-4">
<textarea class="form-control" id="address" name="address" placeholder="Enter Address"></textarea>
</div>
</div>
<!-- Prepended text-->
<div class="form-group">
<label class="col-md-4 control-label" for="cell"></label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">Cell</span>
<input id="cell" name="cell" class="form-control" placeholder="Enter Cellphone" type="text" required="">
</div>
</div>
</div>
<!-- Prepended text-->
<div class="form-group">
<label class="col-md-4 control-label" for="fax"></label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">Fax</span>
<input id="fax" name="fax" class="form-control" placeholder="Enter Fax" type="text" required="">
</div>
</div>
</div>
This is what it looks like right now:
This is the effect that I would like:
sourround the form with
for the inputs i think you could use the col-md-6 or 8
also, you can apply multiple col types
for the radio options try something like this
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Option one is this and that—be sure to include why it's great
</label>
</div>.
and always, if you don't like the background color, you could change it in your own CSS file, you even could use the same class for bootstrap and your css (bootstrap is just that, a css)
also, the classes PULL-RIGHT and PULL-LEFT can help you
hope this can help you!
I have a form with a few fields that need to be inline. Bootstrap is not letting me do this, it renders the form fields on a entire line. Also, I would like the labels to be next to the field.
Is it feasible to wrap a subset of fields in a form tag that is set to form-inline, and how do I get the form fields not to break on their own lines. Here is what I am trying to achieve:
Here is what I've tried:
<div class="form-group">
Zipcode <input type="text" data-bind="value: Zipcode" class="form-control">
Response Time <input type="text" data-bind="value: ResponseNumber" class="form-control"> <select data-bind="options: ResponseUnits" />
</div>'
Also, I have not wrapped the form in <form> because I am using <form> to wrap a file dropzone. I am using knockout and ajax, so I don't need to use forms (unless they are required for bootstrap).
looks like from your example you are more after a horizontal style form. use form groups.
https://jsfiddle.net/whxf78zw/1/
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Zipcode:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="zipcode" placeholder="Enter zip">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="responseTime">Response Time:</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="responseTime" placeholder="Enter response time">
</div>
<div class="col-sm-3">
<select class="form-control">
<option>Hours</option>
<option>Days</option>
<option>Weeks</option>
<option>Months</option>
<option>Years</option>
</select>
</div>
</div>
</form>
I'm trying to format a form page with bootstrap, some of the inputs have visible labels and some others don't. According to bootstrap documentation(Column sizing section) I have to wrap in "row" classes to set the size of inputs, but when i add sr-only class to some labels it doesn't fit. Any suggestions? Here is the fiddle, the TypeId and DV are not aligned
General Information
<div class="form-group col-xs-6">
<label class="control-label" for="fullname">Full name</label>
<input id="fullname" name="fullname" type="text"
class="form-control input-md"></input>
</div>
<div class="form-group col-xs-2">
<label class="control-label sr-only" for="TypeId">Type Id</label>
<select id="TypeId" name="TypeId" class="form-control input-md ">
<option value="CC">CC</option>
<option value="NIT">NIT</option>
<option value="NUIP">NUIP</option>
<option value="CE">CE</option>
<option value="PA">PA</option>
<option value="TI">TI</option>
</select>
</div>
<div class="form-group col-xs-3">
<label class="control-label" for="id">Id</label>
<input id="id" name="id" type="text" class="form-control input-md"></input>
</div>
<div class="form-group col-xs-1">
<label class="control-label sr-only" for="DV">DV</label>
<input id="DV" name="DV" type="text"
class="form-control input-md"></input>
</div>
</fieldset>
A quick (and hacky!) fix is to add another label after your sr-only label that contains only a and no for attribute:
DEMO
<div class="form-group col-xs-2">
<label class="control-label sr-only" for="TypeId">Type Id</label>
<label class="control-label"> </label>
<select id="TypeId" name="TypeId" class="form-control input-md ">
<option value="CC">CC</option>
<option value="NIT">NIT</option>
<option value="NUIP">NUIP</option>
<option value="CE">CE</option>
<option value="PA">PA</option>
<option value="TI">TI</option>
</select>
</div>
I was hoping if someone can inform me what I need to do to get the placeholders in the input box for the dates to fit properly.
I've been playing around with the bootstrap code, but can't fit it in properly.
Here is my screen shot:
Here is my code using horizontal forms:
<div class="container nopadding">
<div class="form-group">
<label class="col-sm-2 control-label" for="txtPISIQueueManufacturer">Manufacturer:</label>
<div class="col-sm-2">
<input type="text" class="form-control height-auto" id="txtPISIQueueManufacturer" placeholder="Enter Manufacturer" />
</div>
<label class="col-sm-2 control-label" for="ddlPISIQueueRequestType">Request Type:</label>
<div class="form-group col-sm-3">
<select class="form-control" id="ddlPISIQueueRequestType">
<option>Shipping Information</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</div>
</div>
<div class="form-group col-sm-8">
<label class="control-label col-sm-offset-1">Requested Date:</label>
<input class="height-auto" id="dtePISIQueueRequestedFromDate" placeholder="From Date" type="text" />
<span class="label label-default">To:</span>
<input class="height-auto" id="dtePISIQueueRequestedToDate" placeholder="To Date" type="text" />
</div>
</div>
Your problem lies in your css properties for your input type["text"] or date or any of the sort. Use your browser inspector and look for an excessive padding or line height in your input fields.
I have this code snippet, but this renders dropdown after line break, What's the best bootstrap 3 col class to get it correct? (select dropdown next to input medium-inline)
<form class="form-horizontal well" >
<div class="form-group">
<label class="col-lg-2 control-label">Memory</label>
<div class="col-lg-4">
<div>
<input id="memory" type="text" class="form-control">
</div>
<div class="col-lg-4">
<select id="memoryType" class="form-control">
<option value="GB" selected="selected">GB</option>
<option value="MB">MB</option>
</select>
</div>
</div>
</div>
</form>
Ok, this is how I would do it.
First add the form-inline class to your form.
Then remove the col-lg classes from labels and inputs.
Also remove all un-needed divs too, which results in the below html:
Markup
<form class="form-inline well" >
<div class="form-group">
<label class="control-label">Memory</label>
<input id="memory" type="text" class="form-control">
</div>
<div class="form-group">
<select id="memoryType" class="form-control">
<option value="GB" selected="selected">GB</option>
<option value="MB">MB</option>
</select>
</div>
</form>
Screen grab
If you want your form-fields to align horizontally - you can actually use the inline form. eg:
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="memory">Memory</label>
<input id="memory" type="text" class="form-control">
</div>
<div class="form-group">
<select id="memoryType" class="form-control">
<option value="GB" selected="selected">GB</option>
<option value="MB">MB</option>
</select>
</div>
</form>
Note: not tested in an actual browser...