How to get Bootstrap 3 Datepicker display in this picture? - css

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.

Related

How to move this Bootstrap login form to center of viewport

How can I set the login view to center of screen? No matter what I try it gets messy. I'm new to Bootstrap and coding.
I've tried align items center and justify but they don't seem to work.
<h2 style="padding-top: 50px">Welcome to Portal.</h2>
<hr/>
<h4 style="padding-top: 20px">Please log in to continue.</h4>
<div class="row justify-content-center" style="padding-top: 30px">
<div class="col-6">
<section id="loginForm">
#using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.Email, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Email, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Email, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Password, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.PasswordFor(m => m.Password, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
#Html.CheckBoxFor(m => m.RememberMe)
#Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-primary" />
</div>
</div>
<p>
#Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>
}
</section>
</div>
</div>
Desired output:
My output:
Try adding d-flex to your row so that the justify content center works.
Wrap your login div with a container with max-width. That will solve your problem.
This will make sure the container is position centered.
I have removed the justify-content-center and extra col-6 that you had put for the login section and wrapped it with a container with max-width.
<h2 class="mt-3">Welcome to Portal.</h2>
<hr/>
<div class="container mt-5" style="max-width:400px">
<h4 class="mt-2">Please log in to continue.</h4>
<div class="row">
<section id="loginForm">
#using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.Email, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Email, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Email, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Password, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.PasswordFor(m => m.Password, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
#Html.CheckBoxFor(m => m.RememberMe)
#Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-primary" />
</div>
</div>
<p>
#Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>
}
</section>
</div>
</div>
To center the content from top and bottom add align-items-center to row , and And pay attention plz , you must give height to row
and for left and right use width : max-content , margin : 0 auto
see this :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>asdasd</title>
<link rel="stylesheet" href="css/general/bootstrap.css">
<style>
.row{
height: 100vh;
}
.main_field{
width: max-content;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row align-items-center">
<div class="main_field">
<form>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>

ASP:NET web api problem with dropdown menu

I'm making Hotel management web app, and working on part where i need to add rooms ,problem is with dropdown menu, while adding knew code , I don't know why my dropdown menu stopped working ,it wokrked perfectly before but when added another part of code, dropdown just stoped wokring(when i click on it it wont drop), i removed code that i added before but a dropdown menu still doesent work.I added the part with the dropdown menu below
**index.cshtlm**
#model HotelManagement.ViewModel.RoomViewModel
{
ViewBag.Title = "Index";
}
<pre>
<div id="divAddRoom" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Room</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="form-group ">
</pre>
#Html.LabelFor(model => model.RoomNumber)
#Html.TextBoxFor(model => model.RoomNumber, new { #class = "form-control", id = "txtRoomNumber" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.RoomPrice)
#Html.TextBoxFor(model => model.RoomPrice, new { #class = "form-control", id = "txtRoomPrice" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.BookingStatusId)
#Html.DropDownListFor(model => model.BookingStatusId, #Model.ListOfBookingStatus, new { #class = "form-control", id = "ddBookingStatus" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomTypeId)
#Html.DropDownListFor(model => model.RoomTypeId, #Model.ListOfRoomType, new { #class = "form-control", id = "ddRoomType" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomCapacity)
#Html.TextBoxFor(model => model.RoomCapacity, new { #class = "form-control", id = "txtRoomCapacity" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomDescription)
#Html.TextBoxFor(model => model.RoomDescription, new { #class = "form-control", id = "txtRoomDescription" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.RoomImage)
<input id="UpLoadImage" type="file" class="form-control" name="roomImage" title="Load Image" onchange="DisplayImage(this)" />
<img id="imgRoom" height="200" width="280" style="border:solid" />
</div>
</div>
</div>
<div class="modal-footer">
<button id="btnSave" type="button" class="btn btn-success">Save</button>
<button type="button" data-dismiss="modal" class="btn btn-danger">Close</button>
</div>
</div>
</div>
Room_controler
enter code here
public ActionResult Index(){
RoomViewModel objRoomViewModel = new RoomViewModel();
objRoomViewModel.ListOfBookingStatus = (from obj in objHotelDbEntities.BookingStatus
select new SelectListItem()
{
Text = obj.BookingStatus,
Value = obj.BookingStatusId.ToString()
}).ToList();
objRoomViewModel.ListOfRoomType = (from obj in objHotelDbEntities.RoomTypes
select new SelectListItem()
{
Text = obj.RoomTypeName,
Value = obj.RoomTypeId.ToString()
}).ToList();
return View(objRoomViewModel);
}
image of the problem

How to change MVC 5 #Html.EditorFor width

I am designing an edit form using MVC 5 Razor. I want the input controls to fill the whole blank width as shown in the picture but it is not working. see image here.
Page here
I have put controls inside table dimensions. One dimension is for the label and the other dimension is for input editor (HTML Helper).
I have tried to override the form-control width with the following css class but no success:
.form-control {
width: 100%!important;
}
and even made another css class
.newinputwidth {
width: 400px!important;
}
but it does not change the width of input.
The full MVC code is here.
#model test2.Models.CaseReport
<style>
.form-control {
width: 100%!important;
}
.newinputwidth {
width: 400px!important;
}
</style>
<h2>Edit</h2>
<div class="container">
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12">
<table id="dt" class="table table-condensed table-responsive table-bordered" width="100%" cellspacing="0">
<tr>
<td>Main Id</td>
<td>
#Html.EditorFor(model => model.CaseReportId, new { htmlAttributes = new { #class = "newinputwidth" } })
</td>
</tr>
<tr>
<td>Location</td>
<td>
#Html.EditorFor(model => model.Location, new { htmlAttributes = new { #class = "form-control" } })
</td>
</tr>
<tr>
<td>Disease </td>
<td>
#Html.EditorFor(model => model.ReportDate, new { htmlAttributes = new { #class = "form-control" } })
</td>
</tr>
</table>
</div>
<div class="row col-lg-12 col-md-12 col-xs-12 text-center">
<div>
<div>
#Html.Action("_DetailsIndex", new { id = Model.CaseReportId })
</div>
</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>
<div>
#Html.ActionLink("Back to List", "Index")
</div>
</div>
}
</div>
In bootstrap, you put blank controls in a container class and apply custom css on it. That will take care of the width of the blank controls. Now, sometimes even when you set container class's width, it does not mean it is responsive or it really makes controls width so short! To achieve responsive desired behavior readable to users set css for each control and apply # style="100% !important; min-width:300px;".
Here is an example:
#using (Html.BeginForm("Register", "Account", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{ <div class="container" style="width:40%; margin:6%">
<h4 style="color:darkorange">Register</h4>
<div class="row text-center">
<h5 style="color:tomato">#ViewBag.Message</h5>
</div>
#Html.AntiForgeryToken()
<div class="form-horizontal">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.FirstName, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { #class = "form-control", #placeholder = "First Name", #style = "width:100% !important; min-width:180px;" } })
#Html.ValidationMessageFor(model => model.FirstName, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
}
Since you're using Bootstrap, I would suggest abandoning the table completely for this type of layout.
You should be able to achieve this with the grid system using a horizontal form:
http://getbootstrap.com/css/#forms-horizontal
<div class="row form-horizontal">
<div class="col-md-12">
<div class="form-group">
#Html.LabelFor(model => model.CaseReportId, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.CaseReportId, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Location, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.Location, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ReportDate, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.ReportDate, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
</div>
</div>
If you really want to use a table, I noticed you have a table-responsive class on the table element. This is meant to be used on a parent (wrapper) div.
http://getbootstrap.com/css/#tables-responsive
<div class="table-responsive">
<table class="table">
...
</table>
</div>

Not able to left justify a DropDownListFor

I have an Html.DropDownListFor with BootStrap that is not left justifying like the Html.TextBoxFor in my form. I've tried both the "pull-left" and "text-left" with no luck. When I look at page with the Developer Tools there doesn't look to be anything that I can see causing a problem.
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Submitter Information</h3>
</div>
<div class="panel-body">
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeId, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeId, new { #class = "col-md-8 form-control", #readonly = "true" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeName, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeName, new { #class = "col-md-8 form-control", autofocus = true, #placeholder = "Employee Name" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeEmail, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeEmail, new { #class = "col-md-8 form-control", #placeholder = "Email Address" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.SelectedEmployeeCo, new { #class = "col-md-4 control-label text-right" })
<div class="col-md-8 pull-left">
#Html.DropDownListFor(x => x.SelectedEmployeeCo,
new SelectList(Model.Companies, "Co", "Name"),
"-- Select Company --",
new {#class = "form-control text-left" })
</div>
</div>
</div>
</div>
I changed some things around and this should have been obivious to me since I was doing the same thing for the other TextBoxFor. I ended up moving the column class into the CSS directly on the DropDownListFor instead of in a separate div. I would have thought it would render the same but it doesn't. So, the point here is to be consistent. Either wrap each control in a div with the column CSS or apply the CSS directly on the control.
This is how I fixed it.
<div class="row form-group">
#Html.LabelFor(m => m.SelectedEmployeeCo, new { #class = "col-md-4 control-label text-right" })
#Html.DropDownListFor(x => x.SelectedEmployeeCo,
new SelectList(Model.Companies, "Co", "Name"),
"-- Select Company --",
new { #class = "col-md-8 form-control pull-left" })
</div>

How increase length of input form in EditorFor in ASP.MVC bootstrap template?

I use bootstrap template on ASP.MVC (but it's minor fact). I have this code on View:
<div class="form-group">
#Html.LabelFor(model => model.udk_number, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.udk_number, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.udk_number, "", new { #class = "text-danger" })
</div>
</div>
But #Html.EditorFor have limited length. How i can increase length of this input?
Similar problem i have and with TextArea:
<div class="form-group">
<label class="col-lg-2 control-label" for="annotation_ru">Аннотация(RU)</label>
<div class="col-lg-10">
<textarea class=form-control id="annotation_ru" name="annotation_ru" rows="3" cols="100"></textarea>
<span class="field-validation-valid text-danger" data-valmsg-for="annotation_ru" data-valmsg-replace="true"></span>
</div>
</div>
I can stretch this area only to the same length as that of the input in example above.
Style your <input> fields using CSS. I usually make them 100% wide so that they are nice and responsive.
input[type=text],
textarea {
width: 100%;
}

Resources