Thanks to James Donnelly, this has been solved. My example has been updated to the working solution.
My reputation isn't high enough so I can't post an image, so I am going to try and describe it as best as possible. I have 7 textboxes and a textarea on a form, and when I load the page, it currently loads each textbox on a separate line.
However, I want the textboxes to load like this:
1 2 3
4 5 6 7
---8--- (span across)
Should I put each row inside a div? I tried floating each textbox to the left, but that does not work correctly. I have Twitter bootstrap setup in my project if that makes things easier.
Here is my working code:
<div class="well">
<h4>Enter Movie in System:</h4>
#using (Html.BeginForm()) {
<div>
<div class="input-prepend">
<span class="add-on"><i class="icon-film"></i></span>
#Html.TextBoxFor(m => m.Title, new { placeholder = "Title" })
#Html.ValidationMessageFor(m => m.Title)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-facetime-video"></i></span>
#Html.TextBoxFor(m => m.Director, new { placeholder = "Director" })
#Html.ValidationMessageFor(m => m.Director)
</div>
#* Make dropdown *#
<div class="input-prepend">
<span class="add-on"><i class="icon-tags"></i></span>
#Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
#Html.ValidationMessageFor(m => m.parentGenre)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-star-empty"></i></span>
#Html.TextBoxFor(m => m.Stars, new { placeholder = "Actor" })
#Html.ValidationMessageFor(m => m.Stars)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-time"></i></span>
#Html.TextBoxFor(m => m.Duration, new { placeholder = "Duration (mins)" })
#Html.ValidationMessageFor(m => m.Duration)
</div>
#* Make dropdown *#
<div class="input-prepend">
<span class="add-on"><i class="icon-warning-sign"></i></span>
#Html.TextBoxFor(m => m.Rating, new { placeholder = "Rating" })
#Html.ValidationMessageFor(m => m.Rating)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-calendar"></i></span>
#Html.TextBoxFor(m => m.releaseDate, new { placeholder = "Release Date" })
#Html.ValidationMessageFor(m => m.releaseDate)
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-comment"></i></span>
#Html.TextAreaFor(m => m.Description, new { placeholder = "Description", #class="input-xxlarge" })
#Html.ValidationMessageFor(m => m.Description)
</div>
</div>
<p>
<button class="btn" type="submit" value="Register">Register</button>
</p>
#Html.ValidationSummary()
</div>
}
.content-group is by default set to display:table; which is what's forcing each of your inputs down onto a new line. You'd simply need to put each of your .input-prepend containers into just one container:
<div>
<div class="input-prepend">
<span class="add-on"><i class="icon-tags"></i></span>
#Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
#Html.ValidationMessageFor(m => m.parentGenre)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-tags"></i></span>
#Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
#Html.ValidationMessageFor(m => m.parentGenre)
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-tags"></i></span>
#Html.TextBoxFor(m => m.parentGenre, new { placeholder = "Genre" })
#Html.ValidationMessageFor(m => m.parentGenre)
</div>
</div>
Is this what u mean?
<div>
<input id="tbx1" />
<input id="tbx2" />
<input id="tbx3" /><br />
<input id="tbx4" />
<input id="tbx5" />
<input id="tbx6" />
<input id="tbx7" />
<span id="span1" style="padding-left:200px">
<input id="tbx8" />
</span>
</div>
you have to post the css style you have tried. but I am guessing that giving the form a float left, width and height should let you be able to float the input fields, make sure none of the first six inputs is greater than 30% of the form width. for the last one width 100%
Related
I want to use label as used "Static Control" label on that page. However, although I use the same Bootstrap version, I cannot aligned my form controls like that (I want the label is right float, data fields is left float -side by side - and there is a ":" sign between them. Howwver, the result is as shown on the image below. Could you please have a look at my code and inform what is wrong?
The code on that page:
<div class="form-group">
<label class="col-md-3 control-label">Static Control</label>
<div class="col-md-9">
<p class="form-control-static"> email#example.com </p>
</div>
</div>
The code I use on my Razor page:
<div class="form-group">
#Html.LabelFor(m => m.Name, new { #class = "col-md-3 control-label" }):
<div class="col-md-9">
#Html.DisplayFor(m => m.Name, new { #class = "form-control-static" })
</div>
</div>
<br />
<div class="form-group">
#Html.LabelFor(m => m.Surname, new { #class = "col-md-3 control-label" }):
<div class="col-md-9">
#Html.DisplayFor(m => m.Surname, new { #class = "form-control-static" })
</div>
</div>
You have two elements which equal 100% width plus the colon, so it pushes the value down a line. You'll need to just code the label instead of using an HtmlHelper to add the colon. Change it to this:
<div class="form-group">
<label class="col-md-3 control-label">#Model.Name:</label>
<div class="col-md-9">
#Html.DisplayFor(m => m.Name, new { #class = "form-control-static" })
</div>
</div>
Here is the final solution fixed the problem. Thanks a lot for all of your helps...
<style>
.col-sm-3 .control-label {
float: right !important;
margin-top: 0 !important;
}
/*Add colon ( : ) to the end of labels */
.col-sm-3 > label:after {
content: " :";
}
</style>
<div class="form-group">
<div class="col-sm-3">
#Html.LabelFor(m => m.Name, new { #class = "control-label" })
</div>
<div class="col-sm-9">
#Html.DisplayFor(m => m.Name)
</div>
</div>
<br />
<div class="form-group">
<div class="col-sm-3">
#Html.LabelFor(m => m.Surname, new { #class = "control-label" })
</div>
<div class="col-sm-9">
#Html.DisplayFor(m => m.Surname)
</div>
</div>
<br />
I really don't know what I'm doing wrong. I want my textboxes with same size of my buttons below. I already tried change a lot in the cshtml but without success.
Below my cshtml file:
#model SomeModel.Models.LoginViewModel
<div class="row">
<div class="col-md-8 col-sm-12 col-xs-12">
<section id="loginForm">
#using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
<hr />
#Html.ValidationSummary(true)
<div class="form-group">
#Html.LabelFor(m => m.UserName, new { #class = "col-md-2 control-label" })
<div class="col-md-12">
#Html.TextBoxFor(m => m.UserName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Password, new { #class = "col-md-2 control-label" })
<div class="col-md-12">
#Html.PasswordFor(m => m.Password, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-xs-12">
<button type="submit" class="btn btn-success btn-block">Entrar</button>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
<button type="submit" class="btn btn-primary btn-block">Ainda Não Tenho Conta</button>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
<button type="submit" class="btn btn-info btn-block">Esqueci Meu Usuário Ou Senha</button>
</div>
</div>
<p>
#Html.ActionLink("Register", "Register") if you don't have a local account.
</p>
}
</section>
</div>
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
What am I doing wrong?
The default MVC5 template has a css rule in Site.css:
input, select, textarea { max-width: 280px; }
I usually remove this rule.
It causes problems with Bootstrap v3 input group where the input box does not extend to its container's width.
In my project I have a form with three inputs, and for all I want to use the input-group and input-group-addon offered by Bootstrap. If I use the following code,
<div class="input-group form-group">
<span style="text-align:left;" class="input-group-addon">... vs Frank</span>
#Html.TextBoxFor(model => model.vsFrank, new { #class = "form-control" })
</div>
<div class="input-group form-group">
<span style="text-align:left;" class="input-group-addon"> ... vs any other guy</span>
#Html.TextBoxFor(model => model.vsAnyOther, new { #class = "form-control" })
</div>
<div class="input-group form-group ">
<span style="text-align:left;" class="input-group-addon">... vs any other monster</span>
#Html.TextBoxFor(model => model.vsAnyMonster, new { #class = "form-control" })
</div>
the result looks like this,
Now, I'd like to have the labels of the last two rows lined up, but the one of the first row shorter. If I add some width to them, as follows,
<div class="input-group form-group">
<span style="width:15ch; text-align:left;" class="input-group-addon">... vs Frank</span>
#Html.TextBoxFor(model => model.vsFrank, new { #class = "form-control" })
</div>
<div class="input-group form-group">
<span style="width:25ch; text-align:left;" class="input-group-addon"> ... vs any other guy</span>
#Html.TextBoxFor(model => model.vsAnyOther, new { #class = "form-control" })
</div>
<div class="input-group form-group ">
<span style="width:25ch; text-align:left;" class="input-group-addon">... vs any other monster</span>
#Html.TextBoxFor(model => model.vsAnyMonster, new { #class = "form-control" })
</div>
the result looks like this:
Now the whole first control is shortened! How can I prevent that without giving all the controls explicit width?
Add a min-width for the input-group.
CSS
.input-group {
min-width: 100%;
}
HTML
<div class="row">
<div class="col-md-3">
<div class="input-group form-group">
<span style="width:15ch; text-align:left;" class="input-group-addon">... vs Frank</span>
<input class="form-control">
</div>
<div class="input-group form-group">
<span style="width:25ch; text-align:left;" class="input-group-addon">... vs any other guy</span>
<input class="form-control">
</div>
<div class="input-group form-group">
<span style="width:25ch; text-align:left;" class="input-group-addon">... vs any other monster</span>
<input class="form-control">
</div>
</div>
</div>
Bootply
I've got display problem when using http://eternicode.github.io/bootstrap-datepicker in Bootstrap 3.
How to get datepicker in this picture?
I'm using MVC 5 with auto generated views
Create.cshtml
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="input-group date" id="dp3">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control datepicker", #readonly = "readonly" } })
<span class="btn btn-default input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
</div>
UPDATE:
Now it looks like better but a little long, how to set the length?
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="col-md-4">
<div class="input-group date">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control date", #readonly = "readonly" } })
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
</div>
Hope this helps. I just added some class and change some tag. It will look like this
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="input-group col-md-10">
<input type="text" class="form-control input-group date" id="dp3">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control datepicker", #readonly = "readonly" } })
<span class="btn btn-default input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
Update:Take a look at the "Column sizing" subsection here
Try to follow this format:
<div id="datetimepicker1" class="input-append date">
<input data-format="dd/MM/yyyy hh:mm:ss" type="text"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar">
</i>
</span>
</div>
The default site.css created when you make a new project has a max-width set on the input element:
/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}
Remove or comment this out and your col-md-10 will work perfect.
Hi I am Having a View Where I am using Kendo Grid.I am editing the row of the table but getting the error.Here is my Code goes.
#(Html.Kendo().Grid<Invoice.Models.ViewModels.Setup.AccountViewModel>()
.Name("Account")
.Columns(columns =>
{
columns.Bound(p => p.AccountID).Title("ID").Width(250);
columns.Bound(p => p.AccountType).Title("Account Type").Width(225);
columns.Bound(p => p.AccountName).Title("Account Name").Width(225);
columns.Bound(p => p.Currency).Title("Currency").Width(225);
columns.Bound(p => p.Status).ClientTemplate("#=data.Status#").Width(225).HtmlAttributes(new {style="text-align:center"});
//columns.Command(command => command.Custom("Edit").Click("showDetails")).Title("Action").Width(150);
columns.Command(command => { command.Edit();}).Width(90);
})
.ToolBar(toolbar =>
{
toolbar.Template(#<text>
<div class="row-fluid">
<div class="span1">
<div class="toolbar" style="height:25px;">
<ul id="menu" style="width:38px; margin-left:22px;" class="span6">
<li style="width:36px;">
<i class="fa fa-plus"></i>
<ul>
#foreach (var account in #ViewBag.AccountType)
{
<li style="width:100px;" class="openid">
#if (#account.Value == "Bank")
{
<label id="Bank1">#account.Value</label>
}
#if (#account.Value == "CreditCard")
{
<label id="Credit">#account.Value</label>
}
#if (#account.Value == "Cash")
{
<label id="Cash1">#account.Value</label>
}
</li>
}
</ul>
</li>
</ul>
</div>
</div>
</div>
</text>);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:550px;" })
//.Selectable(selectable => selectable
//.Mode(GridSelectionMode.Multiple))
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("UpdateAccount"))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
//.ServerOperation(true)
.Model(model => model.Id(p => p.AccountID))
.Read(read => read.Action("Account_Read", "Setup"))
.Create(c => c.Action("Account_Create", "Setup"))
.Update(u => u.Action("Account_Update","Setup"))
)
)
Now the thing is that I am fetching the "Status" from the database that is a HTML tag <span class="label label-success">Active</span> and converting this into the label As Active,InActive and Blocked and Displaying it into the Grid but the problem is that when i am editing this i am getting this error.
"A potentially dangerous Request.Form value was detected from the client (Status="
Here i am using My own template as
UpdateAccount(.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("UpdateAccount")))
wherein i am not including the Status Field but still getting this error.
My UpdateAccount template is as Follows:
<input type="hidden" name="AccountID" id="AccountID" />
<div class="control-group">
<label class="control-label">Account Type</label>
<div class="controls">
<input type="text" name="AccountType" id="AccountType" />
</div>
</div>
<div class="control-group">
<label class="control-label">Account Name</label>
<div class="controls">
<input type="text" name="AccountName" id="AccountName" />
</div>
</div>
<div class="control-group">
<label class="control-label">Currency</label>
<div class="controls">
<input type="text" name="Currency" id="Currency" />
</div>
</div>
Please help me !!!
You can set a template for just one column like this :
columns.Bound(p => p.AccountType)
.Title("Account Type")
.Width(225)
.Template(#<img src="./Images/accountIco.png" title="#item.AccountName" />#item.AccountType);