<form class="form-horizontal" action="#" data-th-action="#{/admin/role/permission/save}" data-th-object="${permission}" method="post">
<div class="form-group">
<label class="col-sm-5 control-label" data-th-text="#{permission.list.permission.label}">Permission</label>
<div class="col-sm-7">
<input type="text" hidden="hidden" data-th-value="*{id}" data-th-field="*{id}" ></input>
<input type="text" class="form-control" data-th-value="*{permissionname}" data-th-field="*{permissionname}" ></input>
</div>
</div>
<div class="form-group" th:each="role : ${allRoles} ">
<label class="col-sm-5 control-label" data-th-text="${role.rolename}">Role 1</label>
<div class="col-sm-7">
<input type="checkbox" th:field="*{permRoles}" th:value="${role}"></input>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-7" >
<button type="submit" class="btn btn-primary" name="action"
data-th-value="#{button.action.save}" data-th-text="#{button.label.save}" >Save</button>
<button type="submit" class="btn btn-default active" name="action"
data-th-value="#{button.action.cancel}" data-th-text="#{button.label.cancel}">Cancel</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-7" >
<p class="text-danger" data-th-if="${#fields.hasErrors('permissionname')}"
data-th-errors="*{permissionname}">type error</p>
</div>
</div>
</form>enter code here
above is the html code , I have a permission object, and wants to assign list of roles to it by using the checkbox, the pass the object back to controller. But the value is not assigned to permission.permroles.
#RequestMapping(value = "/save", method = RequestMethod.POST)
#PreAuthorize("hasRole('PERMISSION_SAVEORADD')")
public ModelAndView savePermission(#ModelAttribute Permission permission, BindingResult result)
throws PermissionNotFoundException {
System.out.println(permission.getPermRoles().size());
permissionDao.updatePermission(permission);
return new ModelAndView("redirect:/admin/role/permission/list");
}
The above is my controller
please help, i am stuck for days.
thank you in advance
I think you could try to solve your problem using hidden input with underscore prefix.
<form th:action="#{${flowExecutionUrl}(_eventId='change')}" th:method="post">
<input type="hidden" name="_fooBar" th:value="${fooBar}"/>
<input type="checkbox" id="fooBar" name="fooBar" th:checked="${fooBar}" />
<!-- rest of code ommited -->
</form>
I had simmilar issue, see my blog post http://lukasgrygar.com/thymeleaf/thymeleaf-tips-and-tricks/#fix-of-problem-with-unchecked-checbox-when-using-thymeleaf-and-spring-web-flow
Related
<div class="form-group row">
<label asp-for="EmployeeEditProperty.Name" class="col-sm-2 col-form-label">
</label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Name" class="form-control" placeholder="Name">
</div>
</div>
<div class="form-group row">
<label asp-for="EmployeeEditProperty.Email" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Email" class="form-control" placeholder="Email">
</div>
</div>
Data not passing to
Employee employee= _EmployeeList.FirstOrDefault(e => e.ID == UpdatedEmployee.ID);
if(employee !=null)
{
employee.Name = UpdatedEmployee.Name;
employee.Email = UpdatedEmployee.Email;
employee.Department = UpdatedEmployee.Department;
}
The properties in view should match the property name in your post action,
You can check my demo:
<form method="post">
<div class="form-group row">
<input hidden asp-for="EmployeeEditProperty.ID" value="1" />
</div>
<div class="form-group row">
<label asp-for="EmployeeEditProperty.Name" class="col-sm-2 col-form-label">
</label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Name" class="form-control" placeholder="Name">
</div>
</div>
//....
<input type="submit" value="Submit" />
The property names EmployeeEditProperty, so in post method, it should be EmployeeEditProperty too:
public ******(Employee EmployeeEditProperty)
Result:
Model Binding in razor pages, you can check this article
I am in need of some advice. I am wanting to implement my own custom editor for a specific object type, Address. I started by reading the documentation for Tag Helpers on the .NET Core website and then read about View Components on the Core site and neither really made since for my exact scenario.
I have a model Address:
public class Address
{
public Guid Id { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string StateCode { get; set; }
public string PostalCode { get; set; }
}
I want to create either a custom editor template, tag helper, or view component that will allow me to do something like this (In my "Edit" View):
#model TestApplication.Models.Customer
<h2>Edit Customer</h2>
<form asp-action="Edit">
<div class="form-horizontal">
<h4>Edit Customer</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
<address-editor asp-for="HomeAddress" />
<address-editor asp-for="WorkAddress" />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</form>
I would like the HTML to be rendered like so:
Edit Customer
<form asp-action="Edit">
<div class="form-horizontal">
<h4>Edit Customer</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="Name" name="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
<h4>Home Address</h4>
<input type="hidden" asp-for="HomeAddress_Id" />
<div class="form-group">
<label asp-for="HomeAddress_AddressLine1" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="HomeAddress_AddressLine1" name="HomeAddress_AddressLine1" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="HomeAddress_AddressLine2" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="HomeAddress_AddressLine2" name="HomeAddress_AddressLine2" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="HomeAddress_City" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="HomeAddress_City" name="HomeAddress_City" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="HomeAddress_StateCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="HomeAddress_StateCode" name="HomeAddress_StateCode" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="HomeAddress_PostalCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="HomeAddress_PostalCode" name="HomeAddress_PostalCode" class="form-control" />
</div>
</div>
<h4>Work Address</h4>
<input type="hidden" asp-for="WorkAddress_Id" />
<div class="form-group">
<label asp-for="WorkAddress_AddressLine1" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="WorkAddress_AddressLine1" name="WorkAddress_AddressLine1" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="WorkAddress_AddressLine2" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="WorkAddress_AddressLine2" name="WorkAddress_AddressLine2" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="WorkAddress_City" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="WorkAddress_City" name="WorkAddress_City" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="WorkAddress_StateCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="WorkAddress_StateCode" name="WorkAddress_StateCode" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="WorkAddress_PostalCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input id="WorkAddress_PostalCode" name="WorkAddress_PostalCode" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</form>
Am I on the right direction by looking into Editor Templates? If so, how do I prefix the control names with the Model.PropertyName (i.e. HomeAddress_)?
I believe my answer came about by researching view components a bit more. I could have gone the direction of a tag helper, view component, or editor template. I decided on view component and needed to know how to pass the entire model information into the view component, well, this question helped me get there. The issue I was having (or question) was that I needed to know about ModelExpression. That class contains everything that I need (name and model), so I was able to do like the following:
<vc:address-editor asp-for="#Model.HomeAddress"></vc:address-editor>
Then, in my AddressEditor ViewComponent, I simply used the two properties that I needed:
public IViewComponentResult Invoke(ModelExpression aspFor)
{
ViewBag.AspFor = aspFor.Name;
return View(aspFor.Model);
}
So, I'm trying to create a controller for an existing table in my database.
This is my Create method:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(ArticleCategoryViewModel model)
{
ArticleCategory cat = new ArticleCategory { Code = model.Code, Name = model.Name, Description = model.Description, VATId = model.VATId };
if (ModelState.IsValid)
{
_context.ArticleCategories.Add(cat);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["VATId"] = new SelectList(_context.VATs, "Id", "Percentage");
return View(model);
}
This is the form from cshtml file for create:
<form asp-action="Create" class="form-horizontal bordered-group" role="form">
<div class="form-horizontal">
<h4>ArticleCategoryViewModel</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Code" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Code" class="form-control" />
<span asp-validation-for="Code" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Description" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="VATId" class="col-md-2 control-label"></label>
<div class="col-md-10">
<select asp-for="VATId" class ="form-control" asp-items="#((IEnumerable<SelectListItem>)ViewData["VATId"])"></select>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default submit" />
</div>
</div>
</div>
</form>
Getting the information from database works, like get for index and details and edit, but when i try to post something like on create or after editing and i click submit button, its just pending. I tried every solution that i could find on the web but nothing works and i have no more ideas.
No logs are written, no error is thrown, nothing happens and i dont know why.
If i put a breakpoint inside the create method, it will not hit, so no debug.
Any ideas ?
I found a problem using Thymeleaf in a Spring Boot application.
Versions:
Spring Boot 1.3.4 and 1.3.3
My Entity:
#Entity
public class MyEntity {
#Id
#GeneratedValue
private Long id;
#Version
private int version;
#DateTimeFormat(pattern="dd/MM/yyyy")
private Calendar calendar;
#DateTimeFormat(pattern="dd/MM/yy")
private Date date;
#NumberFormat(pattern="#0.00000")
private Double aDouble;
}
My Controller:
#RequestMapping(value = "/{myEntity}/edit-form",
method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String editForm(#PathVariable MyEntity myEntity, Model model) {
return "myEntity/edit";
}
My myEntity/edit.html template:
<form class="form-horizontal" method="POST"
data-th-object="${myEntity}"
data-th-action="#{/myEntity/{id}(id=*{id})}">
<input type="hidden" name="_method" value="PUT" />
<div class="form-group"
data-th-classappend="${#fields.hasErrors('calendar')}? 'has-error has-feedback'">
<label for="calendar" class="col-md-3 control-label">Calendar</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{calendar}"/>
<span data-th-text="*{{calendar}}"></span>
</div>
</div>
<div class="form-group"
data-th-classappend="${#fields.hasErrors('date')}? 'has-error has-feedback'">
<label for="date" class="col-md-3 control-label">Date</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{date}"/>
<span data-th-text="*{{date}}"></span>
</div>
</div>
<div class="form-group"
data-th-classappend="${#fields.hasErrors('aDouble')}? 'has-error has-feedback'">
<label for="date" class="col-md-3 control-label">aDouble</label>
<div class="col-md-3">
<input type="text" class="form-control"
data-th-field="*{{aDouble}}"/>
<span data-th-text="*{{aDouble}}"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</form>
When I try to show this page I get:
<body>
<form class="form-horizontal" method="POST" action="/myEntity/1">
<input type="hidden" name="_method" value="PUT" />
<div class="form-group">
<label for="calendar" class="col-md-3 control-label">Calendar</label>
<div class="col-md-3">
<input type="text" class="form-control" id="calendar" name="calendar"
value="java.util.GregorianCalendar[time=1451602800000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Madrid",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=165,lastRule=java.util.SimpleTimeZone[id=Europe/Madrid,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2016,MONTH=0,WEEK_OF_YEAR=53,WEEK_OF_MONTH=0,DAY_OF_MONTH=1,DAY_OF_YEAR=1,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]" />
<span>01/01/2016</span>
</div>
</div>
<div class="form-group">
<label for="date" class="col-md-3 control-label">Date</label>
<div class="col-md-3">
<input type="text" class="form-control" id="date" name="date"
value="2016-02-01 00:00:00.0" />
<span>01/02/16</span>
</div>
</div>
<div class="form-group">
<label for="date" class="col-md-3 control-label">aDouble</label>
<div class="col-md-3">
<input type="text" class="form-control" id="aDouble" name="aDouble"
value="0.1" />
<span>0.10000</span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</form>
</body>
As you can see, the values of all fields aren't formatted as expected (see span which uses the same value through th-text attribute) using toString() method for all values.
Anybody can help me? Thank's in advance.
EDIT 1: I've create a new issue about it
Solved. The problem was in the requestMapping definition:
#RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET,
produces = MediaType.TEXT_HTML_VALUE)
public String editForm(#PathVariable MyEntity myEntity, Model model) {
}
It requires a BindingResult in request context to get PropertyEditor which can transform object value to String. So, including BindingResult in request mapping definition all works as expected:
#RequestMapping(value = "/{myEntity}/edit-form", method = RequestMethod.GET,
produces = MediaType.TEXT_HTML_VALUE)
public String editForm(#ModelAttribute MyEntity myEntity, BindingResult result,
Model model) {
}
Note that object must be annotated with #ModelAttribute and BindingResult must be declared just after #ModelAttribute.
Thank you to everyone who tried to help me.
For date I'd use:
${#dates.format(date, 'dd/MMM/yyyy HH:mm')}
and for numbers:
${#numbers.formatDecimal(num,3,2,'COMMA')}
In documentation it's explained for numbers and dates.
I would like to have the labels not above the input field, but on the left side.
<form method="post" action="" role="form" class="form-inline">
<div class="form-group">
<label for="rg-from">Ab: </label>
<input type="text" id="rg-from" name="rg-from" value="" class="form-control">
</div>
<div class="form-group">
<label for="rg-to">Bis: </label>
<input type="text" id="rg-to" name="rg-to" value="" class="form-control">
</div>
<div class="form-group">
<input type="button" value="Clear" class="btn btn-default btn-clear">
<input type="submit" value="Los!" class="btn btn-primary">
</div>
</form>
This code gives me:
I would like to have:
You can use form-inline class for each form-group :)
<form>
<div class="form-group form-inline">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>
</form>
Put the <label> outside the form-group:
<form class="form-inline">
<label for="rg-from">Ab: </label>
<div class="form-group">
<input type="text" id="rg-from" name="rg-from" value="" class="form-control">
</div>
<!-- rest of form -->
</form>
The Bootstrap 3 documentation talks about this in the CSS documentation tab in the section labelled "Requires custom widths", which states:
Inputs, selects, and textareas are 100% wide by default in Bootstrap.
To use the inline form, you'll have to set a width on the form
controls used within.
If you use your browser and Firebug or Chrome tools to suppress or reduce the "width" style, you should see things line up they way you want. Clearly you can then create the appropriate CSS to fix the issue.
However, I find it odd that I need to do this at all. I couldn't help but feel this manipulation was both annoying and in the long term, error prone. Ultimately, I used a dummy class and some JS to globally shim all my inline inputs. It was small number of cases, so not much of a concern.
Nonetheless, I too would love to hear from someone who has the "right" solution, and could eliminate my shim/hack.
Hope this helps, and props to you for not blowing a gasket at all the people that ignored your request as a Bootstrap 3 concern.
You can create such form where label and form control are side using two method -
1. Inline form layout
<form class="form-inline" role="form">
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
<button type="reset" class="btn btn-default">Reset</button>
<button type="submit" class="btn btn-primary">Login</button>
</form>
2. Horizontal Form Layout
<form class="form-horizontal">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-3">Email</label>
<div class="col-xs-9">
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-3">Password</label>
<div class="col-xs-9">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
</div>
<div class="col-sm-3">
<button type="reset" class="btn btn-default">Reset</button>
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
You can check out this page for more information and live demo - http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-forms.php
Like this
DEMO
HTML
<div class="row">
<form class="form-inline">
<fieldset>
<label class="control-label"><strong>AB :</strong></label>
<input type="text" class="input-mini" >
<label class="control-label"><strong>BIS:</strong></label>
<input type="text" class="input-mini" >
<input type="button" value="Clear" class="btn btn-default btn-clear">
<input type="submit" value="Los!" class="btn btn-primary">
</fieldset>
</form>
</div>
I had the same problem, here is my solution:
<form method="post" class="form-inline form-horizontal" role="form">
<label class="control-label col-sm-5" for="jbe"><i class="icon-envelope"></i> Email me things like this: </label>
<div class="input-group col-sm-7">
<input class="form-control" type="email" name="email" placeholder="your.email#example.com"/>
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Submit</button>
</span>
</div>
</form>
here is the Demo
You can see from the existing answers that Bootstrap's terminology is confusing. If you look at the bootstrap documentation, you see that the class form-horizontal is actually for a form with fields below each other, i.e. what most people would think of as a vertical form. The correct class for a form going across the page is form-inline. They probably introduced the term inline because they had already misused the term horizontal.
You see from some of the answers here that some people are using both of these classes in one form! Others think that they need form-horizontal when they actually want form-inline.
I suggest to do it exactly as described in the Bootstrap documentation:
<form class="form-inline">
<div class="form-group">
<label for="nameId">Name</label>
<input type="text" class="form-control" id="nameId" placeholder="Jane Doe">
</div>
</form>
Which produces:
You must float left all elements like so:
.form-group,
.form-group label,
.form-group input { float:left; display:inline; }
give some margin to the desired elements :
.form-group { margin-right:5px }
and set the label the same line height as the height of the fields:
.form-group label { line-height:--px; }
I think this is what you want, from the bootstrap documentation "Horizontal 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. Doing so changes .form-groups to behave as grid rows, so no need for .row". So:
<form class="form-horizontal" role="form">
<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>
Fiddle: http://jsfiddle.net/beewayne/B9jj2/29/
You can use a span tag inside the label
<div class="form-group">
<label for="rg-from">
<span>Ab:</span>
<input type="text" id="rg-from" name="rg-from" value="" class="form-control">
</label>
</div>
I managed to fix my issue with. Seems to work fine and means I dont have to add widths to all my inputs manually.
.form-inline .form-group input {
width: auto;
}
I am sure you would've already found your answer... here is the solution I derived at.
That's my CSS.
.field, .actions {
margin-bottom: 15px;
}
.field label {
float: left;
width: 30%;
text-align: right;
padding-right: 10px;
margin: 5px 0px 5px 0px;
}
.field input {
width: 70%;
margin: 0px;
}
And my HTML...
<h1>New customer</h1>
<div class="container form-center">
<form accept-charset="UTF-8" action="/customers" class="new_customer" id="new_customer" method="post">
<div style="margin:0;padding:0;display:inline"></div>
<div class="field">
<label for="customer_first_name">First name</label>
<input class="form-control" id="customer_first_name" name="customer[first_name]" type="text" />
</div>
<div class="field">
<label for="customer_last_name">Last name</label>
<input class="form-control" id="customer_last_name" name="customer[last_name]" type="text" />
</div>
<div class="field">
<label for="customer_addr1">Addr1</label>
<input class="form-control" id="customer_addr1" name="customer[addr1]" type="text" />
</div>
<div class="field">
<label for="customer_addr2">Addr2</label>
<input class="form-control" id="customer_addr2" name="customer[addr2]" type="text" />
</div>
<div class="field">
<label for="customer_city">City</label>
<input class="form-control" id="customer_city" name="customer[city]" type="text" />
</div>
<div class="field">
<label for="customer_pincode">Pincode</label>
<input class="form-control" id="customer_pincode" name="customer[pincode]" type="text" />
</div>
<div class="field">
<label for="customer_homephone">Homephone</label>
<input class="form-control" id="customer_homephone" name="customer[homephone]" type="text" />
</div>
<div class="field">
<label for="customer_mobile">Mobile</label>
<input class="form-control" id="customer_mobile" name="customer[mobile]" type="text" />
</div>
<div class="actions">
<input class="btn btn-primary btn-large btn-block" name="commit" type="submit" value="Create Customer" />
</div>
</form>
</div>
You can see the working example here... http://jsfiddle.net/s6Ujm/
PS: I am a beginner too, pro designers... feel free share your reviews.
No CSS required. This should look fine on your page. You can set col-md-* as per your needs
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<div class="row">
<div class="col-md-12">
<form class="form-inline" role="form">
<div class="col">
<div class="form-group">
<label for="inputEmail" class="col-sm-3">Email</label>
<input type="email" class="form-control col-sm-7" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="inputPassword" class="col-sm-3">Email</label>
<input type="password" class="form-control col-sm-7" id="inputPassword" placeholder="Email">
</div>
</div>
<button class="btn btn-primary">Button 1</button>
<button class="btn btn-primary">Button 2</button>
</form>
</div>
</div>
<div class="control-group">
<label class="control-label" for="firstname">First Name</label>
<div class="controls">
<input type="text" id="firstname" name="firstname"/>
</div>
</div>
Also we can use it Simply as
<label>First name:
<input type="text" id="firstname" name="firstname"/>
</label>
It seems adding style="width:inherit;" to the inputs works fine.
jsfiddle demo